You can get started logging with the NLog appender with minimal changes to your project. You essentially just add a few DLLs to your project and then add some configuration details to your .config file specifying an additional (or replacement) log appender. The appender is available via Nuget in Visual Studio and additional documentation can be found on our Github page.
Getting Started Using NuGet
If you’re using NuGet from Visual Studio, you can find and integrate the Stackify NLog libraries and configurations quickly and easily. Just search for Stackify and then install the Stackify NLog Appender.
You can also enter
Install-Package NLog.Targets.Stackify into the package manager console.
Configuring with NuGet
If you are logging errors from a server that doesn’t have a Stackify monitoring agent on it, you have to add an Environment key to the appSettings section of your configuration, as it will not be inferred by Stackify without an agent running on the machine.
In order for the NuGet installation to complete, copy your Stackify Activation Key (license key) from your Retrace account page and paste it here. Once this is complete, you are done with the installation and configuration of the Stackify NLog Appender.
Below is an example of the setting needed if you are logging errors from an unmonitored server:
<appSettings> <add key="Stackify.ApiKey" value="Your Activation Key" /> <add key="Stackify.AppName" value="Your App Name"/> <add key="Stackify.Environment" value="Your Environment"/> <!-- optional - inferred by Stackify if running on a monitored server --> </appSettings>
Advanced Features: GDC, MDC, and NDC
The GDC (Global Diagnostic Context) is a map of name-value pairs that give additional information to the context of the logging event. The GDC is global for all logging event (not thread-scoped). We don’t have access to the entire name-value pair map, but we can access a value given its name. This requires additional configuration in the nLog target. Each GDC field specified (with a non-null value) will be added to the custom properties for the log event.
The MDC (Mapped Diagnostic Context) is a map of name-value pairs that give additional information to the context of the logging event. The MDC is thread-scoped. We don’t have access to the entire name-value pair map, but we can access a value given its name. This requires additional configuration in the nLog target. Each MDC field specified (with a non-null value) will be added to the custom properties for the log event.
The NDC (Nested Diagnostic Context) is a stack of string values that give additional information to the context of the logging event. If the NDC is set, we will get a copy of the top value and add it to the custom properties for the log event. The property will be named “NDC”. No extra configuration is required to use this feature.
<targets> <target name="stackify" type="StackifyTarget" gdcKeys="GDC_Key1, GDC_Key2" mdcKeys="MDC_Key1, MDC_Key2" /> </targets>
Configuring the Logging Levels
First make sure you update your Stackify appender to the latest version. This is necessary for picking up the new logging features.
When installing the Stackify nLog appender, by default it is set up to capture all INFO, WARN, ERROR, and FATAL log levels and display them in the Stackify Portal. To change the minimum logging level, simply change the “minlevel” value. To capture ALL logging messages, change the value above to:
By doing this, you will effectively send all log statements to Retrace and take full advantage of the Log Aggregation feature. You can set the minimum logging level to whatever you would like (DEBUG, INFO, WARN, ERROR, FATAL) to include the types of messages that will be captured by the Stackify Appender.
If you are having issues getting Errors and Logs to come into your account, please see Troubleshoot: Errors and Logs .NET Configurations