我正在配置一个带有应用程序洞察和nlog的.net core 3控制台应用程序
我的代码配置如下
Program.cs
在 appsettings.json 文件中,我有如下内容:
在我的代码中,我使用构造函数注入获取日志记录器,然后只需...
然而,当我运行这个时,在应用洞察中没有得到任何东西。我还注意到在我的输出窗口中,我获得了一些以以下方式开头的日志:
很遗憾没有太多的文档可供参考。有人可以指引我正确的方向吗?
非常感谢。
我的代码配置如下
Program.cs
.ConfigureLogging((hostingContext, logging) =>
{
logging.ClearProviders();
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
logging.AddNLog(NLog.LogManager.LoadConfiguration("nlog.config").Configuration);
})
.ConfigureServices((hostContext, services) =>
{
services.SetupConfiguration(hostContext.Configuration);
services.AddApplicationInsightsTelemetryWorkerService("--AI-Key--");
在我的nlog.config文件中,我有以下内容:
<extensions>
<add assembly="NLog.Web.AspNetCore"/>
<add assembly="Microsoft.ApplicationInsights.NLogTarget" />
</extensions>
<!-- the targets to write to -->
<targets>
<target name="Console" xsi:type="Console" layout="${longdate} ${level} ${message}"/>
<target xsi:type="ApplicationInsightsTarget" name="appInsights" />
</targets>
<!-- rules to map from logger name to target -->
<rules>
<!--All logs, including from Microsoft-->
<logger name="*" minlevel="Trace" writeTo="Console" />
<logger name="*" minlevel="Trace" writeTo="appInsights" />
</rules>
在 appsettings.json 文件中,我有如下内容:
"Logging": {
"LogLevel": {
"Default": "Debug"
}
},
"ApplicationInsights": {
"InstrumentationKey": "--AI-Key--"
},
在我的代码中,我使用构造函数注入获取日志记录器,然后只需...
_logger.LogDebug("something");
然而,当我运行这个时,在应用洞察中没有得到任何东西。我还注意到在我的输出窗口中,我获得了一些以以下方式开头的日志:
Application Insights Telemetry (unconfigured): .....
很遗憾没有太多的文档可供参考。有人可以指引我正确的方向吗?
非常感谢。