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.
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="">