|
| 1 | +[](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 |
0 commit comments