Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
438 views
in Technique[技术] by (71.8m points)

azure - Log4Net AppInsight Adapter Custom property

I have a .NET framework 4.5.2 Application which uses Log4Net for logging. I want to use Azure Application Insights as an interface to view logs of all my application deployments. I installed Microsoft.ApplicationInsights.Log4NetAppender which works fine. 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. 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. What would be the minimal setting to use for that purpose. Here is the default application insight configuration xml file I got. If I remove everything inside the Modules tag It doesn't work as I want.

<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"/>
question from:https://stackoverflow.com/questions/65891434/log4net-appinsight-adapter-custom-property

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...