【发布时间】:2019-12-19 08:02:17
【问题描述】:
我正在使用应用程序洞察力和 nlog 配置 .net core 3 控制台应用程序
我的代码配置如下
程序.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): .....
不幸的是,没有太多的文档可以继续。谁能指出我正确的方向。
非常感谢。
【问题讨论】:
-
您能否提供一个工作示例代码,以及您使用的是哪个 nuget 包?
标签: c# azure azure-application-insights nlog asp.net-core-3.1