Skip to content

hangy/NLog.Targets.ApplicationInsights

Repository files navigation

NLog Target for Application Insights

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.

Installation

To use the NLog target, follow these steps:

  1. Add a reference to the hangy.NLog.Targets.ApplicationInsights NuGet package.

  2. 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>

Known Limitations

  1. Complex objects are flattened when written to customDimensions. #8
  2. 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

Activity Tracing

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 93

Languages