【问题标题】:Does Application Insights data gets sampled when sent from NLog?从 NLog 发送时,Application Insights 数据是否会被采样?
【发布时间】:2021-06-11 14:12:48
【问题描述】:

我想知道如果使用 Application Insights NLog target 从 NLog 发送应用程序洞察数据是否会被采样。

我看过这个页面 Microsoft 文档,Sampling in Application Insights,其中讨论了我们如何控制来自 ASP.NET/ASP.NET Core 项目的遥测采样,但我找不到任何关于数据采样的内容,如果日志是由 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>

【问题讨论】:

    标签: azure-application-insights nlog


    【解决方案1】:

    根据我的测试和搜索,我认为没有办法从 NLog 采样日志跟踪。这是NLog上的所有configurations,没有相关答案。

    我也在搜索启用 Nlog 目标采样的教程,但所有文档都链接到应用程序洞察的采样模块,所以我假设配置也可以在 Nlog 中工作。

    我的测试可以总结为enabling application insightsenable samplingadding Nlog targetmanage NLog 用于应用洞察,结果似乎不走运。

    【讨论】:

      【解决方案2】:

      NLog Target 将根据 LogEvent 自动记录 TraceException。当然可以禁用采样,或者排除TraceException 类型,因此不会生成输出。

      对于旧版 ASP.NET,您可以使用 config-file 执行配置,但对于 ASP.NET Core,您只能使用 configure by code

      default there are 2 TelemetryProcessors,其中一个有ExcludedTypes="event",另一个有IncludedTypes="event"

      • ExcludedTypes 和 IncludedTypes 可以识别这些值 DependencyEventExceptionPageViewRequestTrace

      【讨论】:

      • 嗨@Rolf Kristensen,我看过MS 的遥测采样文档,但它们是否也会影响通过NLog 推送的日志?应用程序中没有 ApplicationInsights.config,并且在启动中未启用 Application Insights 遥测。我只是想确保所有日志(针对所选事件)出现在 Application Insights 中,避免内置采样(如果有)。
      猜你喜欢
      • 1970-01-01
      • 2021-01-28
      • 2019-12-21
      • 2021-11-02
      • 1970-01-01
      • 2021-03-26
      • 1970-01-01
      • 2016-01-13
      • 2016-07-24
      相关资源
      最近更新 更多