Skip to content

Commit 694c8e0

Browse files
committed
Added documentation about Logging framework
1 parent ed927e7 commit 694c8e0

File tree

2 files changed

+103
-9
lines changed

2 files changed

+103
-9
lines changed

Logging.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
[![Generic badge](https://img.shields.io/badge/LOGGING-NEW-GREEN.svg)](https://shields.io/)
2+
3+
# Logging in CyberSource REST Client SDK (.NET)
4+
5+
Since v0.0.1.14, a new logging framework has been introduced in the SDK. This new logging framework makes use of NLog, and standardizes the logging so that it can be integrated with the logging in the client application. The decision to use NLog for building this logging framework has been taken based on benchmark studies that have been made on various logging platforms supported for C#/.NET.
6+
7+
[One such study](https://www.loggly.com/blog/benchmarking-5-popular-net-logging-libraries/) performed benchmarking of five logging frameworks on the market — Log4Net, ELMAH, NLog, Microsoft Enterprise Library, and NSpring. In this study,
8+
9+
> _For heavy-hitting applications that require file logging and speed, NLog was clearly the winner. NLog also has good support from the community with integrationsfor log management solutions._
10+
11+
## NLog Configuration
12+
13+
NLog is a flexible and free logging platform for various .NET platforms, including .NET standard. NLog makes it easy to write to several targets (database, file, console) and change the logging configuration on-the-fly.
14+
15+
Refer this [document of NLog Configuration](https://nlog-project.org/config/) for a complete and detailed description of all the configuration options.
16+
17+
## Setup
18+
19+
In order to leverage the new logging framework, it is required to install the **`NLog.Config`** package into the .NET project. This can be done using the Package Manager, steps for which can be found on the [NuGet page for the package](https://www.nuget.org/packages/NLog.Config/).
20+
21+
When the **`NLog.Config`** package is installed, it will add two new files to the project — **`NLog.config`** and **`NLog.xsd`**.
22+
23+
<span style="color: red;">**Note that the package name is `NLog.Config` and the name of the newly added file is `NLog.config`.**</span>
24+
25+
The **`Copy To Output Directory`** property of this `NLog.config` file needs to be set to **`Copy Always`**.
26+
27+
## Sample NLog.config File
28+
29+
```xml
30+
<?xml version="1.0" encoding="utf-8" ?>
31+
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
32+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33+
autoReload="true"
34+
throwExceptions="false"
35+
throwConfigExceptions="true"
36+
globalThreshold="Trace"
37+
internalLogLevel="Off" internalLogFile="">
38+
39+
<!-- Keeping `globalThreshold` at `Trace` because no log events below `globalThreshold` will be logged, regardless of any rules. -->
40+
41+
<variable name="enableMasking" value="true"/>
42+
43+
<targets>
44+
<target name="file"
45+
xsi:type="File"
46+
layout="[${longdate:universalTime=true}] [${level:uppercase=true}] [${logger:shortName=true}] : ${message}"
47+
fileName="C:\path\to\logs\Application.log"
48+
keepFileOpen="false"
49+
archiveAboveSize="5242880"
50+
archiveNumbering="Date"
51+
archiveDateFormat="yyyymmddhhmmss"/>
52+
<target name="logConsole" xsi:type="Console"
53+
layout="[${longdate:universalTime=true}] [${level:uppercase=true}] [${logger:shortName=true}] : ${message}" />
54+
</targets>
55+
<rules>
56+
<logger name="*" minlevel="Trace" writeTo="file" />
57+
<logger name="*" minlevel="Trace" writeTo="logconsole" />
58+
</rules>
59+
</nlog>
60+
```
61+
62+
### Important Notes
63+
64+
* The logger name in the rule must match the **'Logger name of the Logger object'**. It can include wildcard characters (`*`, `?`).
65+
* The logger name can be the namespace from which logging statements should be honored.
66+
* In case `name="*"` is used, all logging statements from all namespaces will be written to log. This will include logging statements from inside the SDK as well.
67+
* If logging statements from inside the SDK should not be logged, provide specific namespaces in the rules.
68+
* The `minlevel` field denotes the minimum level to log. In a production environment, this may be set to `Warn`.
69+
* The variable `enableMasking` needs to be set to `true` if sensitive data in the request/response should be hidden/masked.
70+
* Sensitive data fields are listed below:
71+
* Card Security Code
72+
* Card Number
73+
* Any field with `number` in the name
74+
* Card Expiration Month
75+
* Card Expiration Year
76+
* Account
77+
* Routing Number
78+
* Email
79+
* First Name & Last Name
80+
* Phone Number
81+
* Type
82+
* Token
83+
* Signature

README.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,26 @@ The CyberSource .NET client provides convenient access to the [CyberSource REST
1010

1111
* Nuget Package Manager
1212

13-
```
13+
```bash
1414
PM> Install-Package CyberSource.Rest.Client
1515
```
1616

1717
## Registration & Configuration
18-
Use of this SDK and the CyberSource APIs requires having an account on our system. You can find details of getting a test account and creating your keys [here](https://developer.cybersource.com/api/developer-guides/dita-gettingstarted/registration.html)
1918

20-
Remember this SDK is for use in server-side .NET applications that access the CyberSource REST API and credentials should always be securely stored and accessed appropriately.
19+
Use of this SDK and the CyberSource APIs requires having an account on our system. You can find details of getting a test account and creating your keys [here](https://developer.cybersource.com/api/developer-guides/dita-gettingstarted/registration.html)
2120

21+
Remember this SDK is for use in server-side .NET applications that access the CyberSource REST API and credentials should always be securely stored and accessed appropriately.
2222

2323
## SDK Usage Examples and Sample Code
24+
2425
To get started using this SDK, it's highly recommended to download our sample code repository:
26+
2527
* [Cybersource C# Sample Code Repository (on GitHub)](https://github.com/CyberSource/cybersource-rest-samples-csharp)
2628

2729
In that respository, we have comprehensive sample code for all common uses of our API:
2830

2931
Additionally, you can find details and examples of how our API is structured in our API Reference Guide:
32+
3033
* [Developer Center API Reference](https://developer.cybersource.com/api/reference/api-reference.html)
3134

3235
The API Reference Guide provides examples of what information is needed for a particular request and how that information would be formatted. Using those examples, you can easily determine what methods would be necessary to include that information in a request using this SDK.
@@ -60,21 +63,29 @@ In order to use OAuth, set the run environment to OAuth enabled URLs. OAuth only
6063
_configurationDictionary.Add("runEnvironment", "api-matest.cybersource.com")
6164
// For PRODUCTION use
6265
// _configurationDictionary.Add("runEnvironment", "api-ma.cybersource.com")
63-
```
66+
```
6467

6568
### Switching between the sandbox environment and the production environment
66-
Cybersource maintains a complete sandbox environment for testing and development purposes. This sandbox environment is an exact duplicate of our production environment with the transaction authorization and settlement process simulated. By default, this SDK is configured to communicate with the sandbox environment. To switch to the production environment, set the `runEnvironment` property in the SDK Configuration. See our sample at https://github.com/CyberSource/cybersource-rest-samples-csharp/blob/master/src/Configuration.cs.
69+
70+
Cybersource maintains a complete sandbox environment for testing and development purposes. This sandbox environment is an exact duplicate of our production environment with the transaction authorization and settlement process simulated. By default, this SDK is configured to communicate with the sandbox environment. To switch to the production environment, set the `runEnvironment` property in the SDK Configuration. See our sample at [the Configuration.cs class in the Sample Codes repository](https://github.com/CyberSource/cybersource-rest-samples-csharp/blob/master/src/Configuration.cs).
6771

6872
```csharp
69-
// For TESTING use
70-
_configurationDictionary.Add("runEnvironment", "apitest.cybersource.com");
71-
// For PRODUCTION use
72-
// _configurationDictionary.Add("runEnvironment", "api.cybersource.com");
73+
// For TESTING use
74+
_configurationDictionary.Add("runEnvironment", "apitest.cybersource.com");
75+
// For PRODUCTION use
76+
// _configurationDictionary.Add("runEnvironment", "api.cybersource.com");
7377
```
7478

7579
API credentials are different for each environment, so be sure to switch to the appropriate credentials when switching environments.
7680

81+
### Logging
82+
83+
[![Generic badge](https://img.shields.io/badge/LOGGING-NEW-GREEN.svg)](https://shields.io/)
7784

85+
Since v0.0.1.14, a new logging framework has been introduced in the SDK. This new logging framework makes use of NLog, and standardizes the logging so that it can be integrated with the logging in the client application.
86+
87+
More information about this new logging framework can be found in this file : [Logging.md](Logging.md)
7888

7989
## License
90+
8091
This repository is distributed under a proprietary license.

0 commit comments

Comments
 (0)