0
votes

I am wondering if the application insights data will get sampled if sent from NLog using Application Insights NLog target.

I have seen this page Microsoft documentation, Sampling in Application Insights, which talks about how we can control the telemetry sampling from ASP.NET/ ASP.NET Core projects, but I couldn't find anything which talks about sampling of data if the logs were sent by NLog.

https://github.com/microsoft/ApplicationInsights-dotnet-logging

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <extensions>
        <add assembly="Microsoft.ApplicationInsights.NLogTarget" />
    </extensions>
    <targets>
        <target xsi:type="ApplicationInsightsTarget" name="aiTarget">
            <instrumentationKey>Your_Resource_Key</instrumentationKey>  <!-- 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>
2

2 Answers

0
votes

Per my testing and searching, I think there's no way to make log traces from NLog sampled. Here's all the configurations on NLog, no related answer.

I also searching for tutorials for enabling sampling for Nlog target, but all the documents linked to the sampling module of application insights, so I assumed that the configuration might work in Nlog too.

My test can be summarized with enabling application insights, enable sampling, adding Nlog target, manage NLog for application insights, and the results seem no luck.

0
votes

NLog Target will automatically log either Trace or Exception depending on the LogEvent. Ofcourse it is possible to disable sampling, or exclude the types Trace and Exception so no output is generated.

For legacy ASP.NET then you can perform configuration using config-file, but for ASP.NET Core then you can only configure by code.

By default there are 2 TelemetryProcessors where one has ExcludedTypes="event" and the other has IncludedTypes="event".

  • ExcludedTypes and IncludedTypes can recognize these values Dependency, Event, Exception, PageView, Request, Trace.