【发布时间】:2021-11-12 10:42:14
【问题描述】:
无法将 Log4Net 日志刷新到用于 net core 3.1 的 Web 应用中的 Azure 应用洞察
这是项目文件。
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 包:
appsettings.json
{
"ApplicationInsights": {
"InstrumentationKey": "<Added instrumentation key here>"
},
"Logging": {
"ApplicationInsights": {
"LogLevel": {
"Default": "Error"
}
}
}
}
【问题讨论】:
标签: .net-core log4net azure-application-insights .net-core-3.1 log4net-appender