This is a logger for sending your NLog logs to Application Insights. It is an inofficial fork of Microsoft.ApplicationInsights.NLog with the addition of some community contributions that did not make it into the official distribution.
This package is scheduled for deprecation. The official Microsoft.ApplicationInsights.NLogTarget package now includes equivalent functionality (currently in beta as 3.x). Once the official package is released as stable, this package will be deprecated and is no longer maintained.
For new projects, please use the official package instead. Existing projects are encouraged to migrate when the official stable release is available.
To use the NLog target, follow these steps:
-
Add a reference to the
hangy.NLog.Targets.ApplicationInsightsNuGet package. -
In your
NLog.config, add the assembly reference to the extension, and set up a logger using your connectionstring<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <extensions> <add assembly="hangy.NLog.Targets.ApplicationInsights" /> </extensions> <targets async="true"> <target xsi:type="ApplicationInsightsTarget" name="aiTarget"> <connectionString>Your_ApplicationInsights_ConnectionString</connectionString> <!-- Only required if not using ApplicationInsights.config --> <contextproperty name="threadid" layout="${threadid}" /> <!-- Can be repeated with more context --> </target> </targets> <rules> <logger name="*" minlevel="Trace" writeTo="aiTarget" /> </rules> </nlog>
- Complex objects are flattened when written to
customDimensions. #8 - Properties with the same name are overwritten. For example, if you have a GDC value named
Name, and a log event property of the same name, the GDC value will be logged. #10
By default, the ApplicationInsightsTarget logs the trace and span information from the current. If you want to disable this behaviour, set the layout as follows:
<target xsi:type="ApplicationInsightsTarget" name="aiTarget" spanId="" traceId="">