我们最近加入了针对AppInsights的Azure应用服务。
我使用下面的代码来使用跟踪:
Trace.WriteLine("Api v1 called by user");
Trace.TraceWarning("Tracking warning via AI");
Trace类是从System.Diagnostics
引用的。
我已根据this页面手动在我的web.config中添加了以下代码。:
<system.diagnostics>
<trace autoflush="false" indentsize="4">
<listeners>
<add name="myListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="TextWriterOutput.log" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
但是,Trace.WriteLine and TraceWarning
事件 NOT 已收集。
对我有用的是直接使用AppInsights遥测库来使用TrackTrace事件,如下所示。
telemetry.TrackTrace("Tracking trace via AI for user:", SeverityLevel.Information); //This works
我想使用Trace WriteLine和TraceWarning ,并希望在AppInsights中看到这些,因为后者要求我们更改TelemetryClient库的所有引用。
我添加了最新的ApplicationInsights.TraceListener NuGet
包。但是,这并没有改变我的web.config文件。我必须手动添加<system.diagnostics>
标记,如上所示。
有什么我想念的吗?