使用Trace.CorrelationManager.ActivityId
作为监听器进行WADLogsTable
跟踪时,是否可以将System.Diagnostics
自动包含在Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener
中?
答案 0 :(得分:1)
新版本的Azure .NET SDK在WAD表中包含一个ActivityId列,您可以使用EventSource派生类包含自定义列(仅在Azure SDK 2.6上验证了这一点,但您需要确保使用它。 NET 4.5.1,因为.NET 4.5.0似乎有一些导致静默失败的错误。)
对于ASP.NET应用程序,在Application_BeginRequest方法中,您将执行以下操作:
protected void Application_BeginRequest()
{
Guid requestId = Guid.NewGuid();
System.Diagnostics.Trace.CorrelationManager.ActivityId = requestId;
System.Diagnostics.Tracing.EventSource.SetCurrentThreadActivityId(requestId);
}
您可以创建自定义的EventSource类,如下所示:
[EventSource(Name="MyCompany-MyProduct-MyEventSource")]
public class MyEventSourceWriter : EventSource
{
public static MyEventSourceWriter Log = new MyEventSourceWriter();
public MyEventSourceWriter()
{
}
public void MyEvent(string myValue1, string myValue2, string myValue3)
{
if (IsEnabled())
{
this.WriteEvent(1, myValue1, myValue2, myValue3);
}
}
}
然后,您可以在您的diagnostics.wadcfgx文件中启用此功能,如下所示:
<EtwEventSourceProviderConfiguration scheduledTransferPeriod="PT1M" provider="MyCompany-MyProduct-MyEventSource">
<Event id="1" eventDestination="MyEvent" />
<DefaultEvents />
</EtwEventSourceProviderConfiguration>
然后,如果您想要实际编写日志条目,您只需在代码中的任何位置执行以下操作:
MyEventSourceWriter.Log.MyEvent("Hello", "World", "That is all.");
然后,在第一次为该事件创建日志条目后(等待Azure Diagnostics提取日志的适当时间),&#34; WADMyEvent&#34;将创建表,它将包含ActivityId,myValue1,myValue2和myValue3的列。
答案 1 :(得分:0)
遗憾的是,无法修改WAD收集的数据格式。