我正在使用应用程序见解和nlog配置.net core 3控制台应用程序>
我的代码配置如下
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): .....
不幸的是,没有太多的文档可以继续。谁能指出我正确的方向。
非常感谢。
我正在使用应用程序见解和nlog配置.net core 3控制台应用程序,我的代码配置如下Program.cs .ConfigureLogging((hostingContext,logging)=> {logging ....