C# 无法将跟踪事件记录到Application Insights
我们最近已将Azure应用程序服务加入AppInsights 我使用以下代码来使用跟踪:C# 无法将跟踪事件记录到Application Insights,c#,azure,logging,trace,azure-application-insights,C#,Azure,Logging,Trace,Azure Application Insights,我们最近已将Azure应用程序服务加入AppInsights 我使用以下代码来使用跟踪: Trace.WriteLine("Api v1 called by user"); Trace.TraceWarning("Tracking warning via AI"); 跟踪类引用自System.Diagnostics 我已手动在我的web.config中添加了以下代码,如下所示: 我想使用Trace WriteLine和TraceWarning并希望在AppInsights中看到它们,因为后
Trace.WriteLine("Api v1 called by user");
Trace.TraceWarning("Tracking warning via AI");
跟踪类引用自System.Diagnostics
我已手动在我的web.config中添加了以下代码,如下所示:
我想使用Trace WriteLine和TraceWarning并希望在AppInsights中看到它们,因为后者要求我们更改遥测客户端库的所有引用
我已经添加了最新的ApplicationInsights.TraceListener NuGet
包。但是,这并没有改变我的web.config文件。我必须手动添加
标记,如上所示。
是否缺少任何内容?添加ApplicationInsights.TraceListener NuGet软件包应自动修改Web.Config,如此链接所示: 如果出于某种原因未修改Web.config,请手动添加以下内容
<system.diagnostics>
<trace>
<listeners>
<add name="myAppInsightsListener" type="Microsoft.ApplicationInsights.TraceListener.ApplicationInsightsTraceListener, Microsoft.ApplicationInsights.TraceListener" />
</listeners>
</trace>
</system.diagnostics>
Btw-如果您的应用程序基于.net core,那么您需要使用tracelistener包的2.6.0-beta3。谢谢@cjthomas。我不得不手动添加这段代码,因为添加NuGet包不会改变web.config。但是,我仍然没有看到System.Diagnostic.Trace。1奇怪的是,在Visual studio中单击“配置AppInsights”选项后,我没有看到“启用日志适配器选项”的选项。我遗漏了什么吗?你用什么工具添加nuget?我使用了Visual Studio 2017,将此nuegt添加到web应用程序修改了web.config。应用程序洞察也会收集跟踪。您是否可以再试一次,并确保修改后的web.config以及applicationinsights.config(包含检测密钥)已复制到部署此项的服务器。请尝试按照此处的说明进行操作,并查看这是否有帮助:
telemetry.TrackTrace("Tracking trace via AI for user:", SeverityLevel.Information); //This works
<system.diagnostics>
<trace>
<listeners>
<add name="myAppInsightsListener" type="Microsoft.ApplicationInsights.TraceListener.ApplicationInsightsTraceListener, Microsoft.ApplicationInsights.TraceListener" />
</listeners>
</trace>
</system.diagnostics>