简体   繁体   English

Log4Net AppInsight 适配器自定义属性

[英]Log4Net AppInsight Adapter Custom property

I have a .NET framework 4.5.2 Application which uses Log4Net for logging.我有一个 .NET 框架 4.5.2 应用程序,它使用 Log4Net 进行日志记录。 I want to use Azure Application Insights as an interface to view logs of all my application deployments.我想使用 Azure Application Insights 作为界面来查看我所有应用程序部署的日志。 I installed Microsoft.ApplicationInsights.Log4NetAppender which works fine.我安装了运行良好的 Microsoft.ApplicationInsights.Log4NetAppender。 However to simplify querying logs I need to add a Custom property.但是,为了简化查询日志,我需要添加一个自定义属性。 I can't find anything on how to do it with the appender settings.我找不到任何关于如何使用 appender 设置的信息。 The only work around I found which works is by adding a telemetry initializer with a the custom property to the project.我发现唯一可行的解决方法是向项目添加带有自定义属性的遥测初始化程序。

The problem is that I don't want to slow down the app with telemetry.问题是我不想通过遥测减慢应用程序的速度。 I just need to set the Custom Property and keep my Log4net only sending data to AppInsights.我只需要设置自定义属性并让我的 Log4net 只向 AppInsights 发送数据。 What would be the minimal setting to use for that purpose.为此目的使用的最小设置是什么。 Here is the default application insight configuration xml file I got.这是我得到的默认应用程序洞察配置 xml 文件。 If I remove everything inside the Modules tag It doesn't work as I want.如果我删除 Modules 标签内的所有内容,它就不能按我的意愿工作。

<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
<TelemetryInitializers>
    <Add Type="Microsoft.ApplicationInsights.DependencyCollector.HttpDependenciesParsingTelemetryInitializer, Microsoft.AI.DependencyCollector"/>
</TelemetryInitializers>
<TelemetryModules>
    <Add Type="Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector">
        <ExcludeComponentCorrelationHttpHeadersOnDomains>
            <!-- 
    Requests to the following hostnames will not be modified by adding correlation headers.         
    Add entries here to exclude additional hostnames.
    NOTE: this configuration will be lost upon NuGet upgrade.
    -->
            <Add>core.windows.net</Add>
            <Add>core.chinacloudapi.cn</Add>
            <Add>core.cloudapi.de</Add>
            <Add>core.usgovcloudapi.net</Add>
        </ExcludeComponentCorrelationHttpHeadersOnDomains>
        <IncludeDiagnosticSourceActivities>
            <Add>Microsoft.Azure.EventHubs</Add>
            <Add>Microsoft.Azure.ServiceBus</Add>
        </IncludeDiagnosticSourceActivities>
    </Add>
</TelemetryModules>
<ApplicationIdProvider Type="Microsoft.ApplicationInsights.Extensibility.Implementation.ApplicationId.ApplicationInsightsApplicationIdProvider, Microsoft.ApplicationInsights"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM