Not able to flush Log4Net logs to azure application insights in the web app for net core 3.1
Here're the project files.
log4net.config
<?xml version="1.0" encoding="utf-8"?>
<log4net>
<!--Application Insights Appender-->
<appender name='aiAppender'
type='Microsoft.ApplicationInsights.Log4NetAppender.ApplicationInsightsAppender,
Microsoft.ApplicationInsights.Log4NetAppender'>
<layout type='log4net.Layout.PatternLayout'>
<conversionPattern value='%message%newline' />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="aiAppender" />
</root>
</log4net>
ApplicationInsights.config
<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
<InstrumentationKey>..Added InstrumentationKey here..</InstrumentationKey>
</ApplicationInsights>
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry();
}
Nuget Packages:
appsettings.json
{
"ApplicationInsights": {
"InstrumentationKey": "<Added instrumentation key here>"
},
"Logging": {
"ApplicationInsights": {
"LogLevel": {
"Default": "Error"
}
}
}
}
I got this working finally by updating ConfigureServices() in Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry(new ApplicationInsightsServiceOptions
{
InstrumentationKey = Configuration["ApplicationInsights:InstrumentationKey"],
EnableActiveTelemetryConfigurationSetup = true
});
}