我升级到 Azure SDK 2.5 并使用 EventSources
切换到语义日志记录。
使用自定义 EventListener
在本地进行日志记录。
部署时,日志会写入存储表,但仅填充 EventId
、Pid
、Tid
等,真正的情况是有趣的字段(消息、任务、关键字、操作码)留空。
诊断基础设施日志充满了有关 ETW 的错误,但我不知道如何理解它们:
Failed to load backup EventSource manifest file C:\Resources\{13b7ec61-6424-d4d3-9972-a83e58d8d6bb}\directory\f71b19461fcf494d89d3717b3a13cadf. something.WorkerRole.DiagnosticStore\WAD0103\Configuration\EventSource_Manifest_fe06b63d-39aa-5419-0529-18c4dacf4f68_Ver_20.backup.xml;
EventSource events will be logged without a proper schema until provider sends the manifest packets
Load manifest file failed for C:\Resources\{13b7ec61-6424-d4d3-9972-a83e58d8d6bb}\directory\f71b19461fcf494d89d3717b3a13cadf.something. WorkerRole. DiagnosticStore\WAD0103\Configuration\EventSource_Manifest_fe06b63d-39aa-5419-0529-18c4dacf4f68_Ver_20.xml
Failed to manage manifest version for file C:\Resources\{13b7ec61-6424-d4d3-9972-a83e58d8d6bb}\directory\f71b19461fcf494d89d3717b3a13cadf. something. WorkerRole.DiagnosticStore\WAD0103\Configuration\EventSource_Manifest_fe06b63d-39aa-5419-0529-18c4dacf4f68_Pid_3436.xml
Failed to process EventSource manifest event GUID:fe06b63d-39aa-5419-0529-18c4dacf4f68, event id:0xFFFE
Change in the number of events lost since the last sample: EventsCaptured=2 EventsLogged=1 EventsLost=0
我不使用 list 文件并通过类/属性名称指定EventSource
:
<EtwEventSourceProviderConfiguration scheduledTransferPeriod="PT3M" scheduledTransferLogLevelFilter="Information" provider="something.Core">
<DefaultEvents eventDestination="CoreEvents" />
</EtwEventSourceProviderConfiguration>
我一定错过了一些东西,但我不知道是什么。
其余的诊断服务全部正常工作(基础设施日志、性能计数器等)。
正在记录的 EventId
是正确的,但日志的所有重要信息都丢失了,我想是因为配置不完整?
编辑:这是我的EventSource
代码。我不会发布整个内容,因为它太大了。我使用另一种类型来调用 EventSource 方法并处理参数格式(如果在该级别中启用了源)。大多数方法参数都是字符串
类型,没有传递对象或其他复杂类型(处理其他类型)。
[EventSource(Name = "something.Core")]
public sealed class CoreEventSource : EventSource {
private static readonly CoreEventSource SoleInstance = new CoreEventSource();
static CoreEventSource() {}
private CoreEventSource() {}
public static CoreEventSource Instance {
get { return SoleInstance; }
}
public static EventKeywords AllKeywords = (EventKeywords)(-1);
public class Keywords {
public const EventKeywords None = (EventKeywords)(1 << 1);
public const EventKeywords Infrastructure = (EventKeywords)(1 << 2);
[...]
}
public class Tasks {
public const EventTask None = EventTask.None;
// generic operations
public const EventTask Create = (EventTask)11;
public const EventTask Update = (EventTask)12;
public const EventTask Delete = (EventTask)13;
public const EventTask Get = (EventTask)14;
public const EventTask Put = (EventTask)15;
public const EventTask Remove = (EventTask)16;
public const EventTask Process = (EventTask)17;
}
[Event(1, Message = "Initialization of {0} failed: {1}.", Level = EventLevel.Critical, Keywords = Keywords.Infrastructure)]
public void CriticalInitializationFailure(string component, string details, string exception) {
this.WriteEvent(1, component, details, exception);
}
[Event(2, Message = "[Role '{0}'] Startup: {1}", Level = EventLevel.Informational, Keywords = Keywords.Infrastructure)]
public void RoleStartup(string roleName, string message) {
this.WriteEvent(2, roleName, message);
}
[Event(3, Message = "[Role '{0}'] Stop failed: {1}.", Level = EventLevel.Error, Keywords = Keywords.Infrastructure)]
public void RoleStopFailed(string roleName, string details, string exception) {
this.WriteEvent(3, roleName, details, exception);
}
[Event(4, Message = "An unhandled exception occurred.", Level = EventLevel.Critical, Keywords = Keywords.Infrastructure)]
public void UnhandledException(string exception) {
this.WriteEvent(4, exception);
}
[Event(5, Message = "An unobserved exception occurred in a faulted task.", Level = EventLevel.Critical, Keywords = Keywords.Infrastructure)]
public void UnobservedTaskException(string exception) {
this.WriteEvent(5, exception);
}
[...]
}
最佳答案
事实证明我的 EventSource
存在不少问题。我向任何使用 ETW 的人推荐的第一件事是使用 Microsoft TraceEvent Library来自 NuGet,即使您使用 System.Diagnostics.Tracing,因为它附带了一个工具,可以验证您的 EventSource 代码并通知您问题。
我必须修复以下问题:
EventSource
名称不得包含句点。
- 任务/操作码对在
EventSource
中必须是唯一的 - 不得在自定义关键字或任务枚举中声明
None
字段
希望这对遇到类似问题的人有所帮助。
关于azure - Azure 诊断 (SDK 2.5) 中的 ETW 事件使用不正确/缺失的架构进行记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27405905/