用mvc在azure表中设置etw日志
本文关键字:设置 etw 日志 mvc azure | 更新日期: 2023-09-27 18:26:37
花了4个多小时试图弄清楚为什么etw日志不会出现在我的表中。我仍然不明白为什么我的日志没有出现在azure表中。
编辑
该服务作为云服务托管。
以下是我的诊断xml的样子。这是通过在visual studio 中选择选项自动生成的
<?xml version="1.0" encoding="utf-8"?>
<DiagnosticsConfiguration xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
<PublicConfig xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
<WadCfg>
<DiagnosticMonitorConfiguration overallQuotaInMB="4096">
<EtwProviders>
<EtwEventSourceProviderConfiguration provider="AzureEventSource">
<Event id="1" eventDestination="Error" />
<Event id="2" eventDestination="Warning" />
<Event id="3" eventDestination="Debug" />
<Event id="4" eventDestination="Performance" />
<DefaultEvents eventDestination="Default" />
</EtwEventSourceProviderConfiguration>
</EtwProviders>
<Logs scheduledTransferPeriod="PT2M" />
</DiagnosticMonitorConfiguration>
</WadCfg>
<StorageAccount />
</PublicConfig>
<PrivateConfig xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration">
<StorageAccount endpoint="" />
</PrivateConfig>
<IsEnabled>true</IsEnabled>
</DiagnosticsConfiguration>
这就是我的课看起来像的样子
using Microsoft.Diagnostics.Tracing;
namespace CommonUtils
internal sealed class AzureEventSource : EventSource, ILogger
{
public AzureEventSource(Type owner) : base(owner.FullName)
{
}
private bool IsInputInvalid(String message)
{
return String.IsNullOrWhiteSpace(message);
}
public void Error(string message, params object[] args)
{
if (IsInputInvalid(message))
{
throw new ArgumentNullException("message");
}
this.WriteEvent(1, string.Format(message, args));
}
}
}
我很确定我错过了一些简单的东西。
任何帮助都将不胜感激
假设您在上面的示例中引用了Microsoft.Diagnostics.Tracing.EventSource。
您的类和方法分别缺少EventSourceEvent属性。
事件源的简单hello世界如下所示。
[EventSource(Name = "HelloEventSource")]
internal sealed class HelloEventSource : EventSource
{
[Event(1, Level = EventLevel.Informational, Message = "Hello World! {0}")]
public void HelloWorld(string name)
{
WriteEvent(1, name);
}
}
您应该修复代码的跟踪部分,并检查日志是否在您的机器/vm上本地生成。接下来是通过您选择的诊断管道发送事件。