我无法让Azure诊断程序吐出任何我的跟踪消息 - 即使是在即将推出的VS2012项目模板中也是如此。这是我做的:
C:\Users\<Username>\AppData\Local\dftmp\Resources\<Instance GUID>\directory\WCFService.WebRole.svclog
=&gt;什么也看不见! 我怎样才能使这个工作?我试图避免使用我自己的手写.txt日志来利用内置的跟踪侦听器框架(以及解析工具)。
WebRole.cs
using System.Diagnostics;
namespace WCFService.WebRole
{
public class WebRole : RoleEntryPoint
{
public override bool OnStart()
{
// To enable the AzureLocalStorageTraceListner, uncomment relevent section in the web.config
DiagnosticMonitorConfiguration diagnosticConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();
diagnosticConfig.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
diagnosticConfig.Directories.DataSources.Add(AzureLocalStorageTraceListener.GetLogDirectory());
string message = "Houston, tracing is broken!";
Trace.TraceError(message);
Trace.TraceInformation(message);
Trace.TraceWarning(message);
Trace.WriteLine(message);
return base.OnStart();
}
}
}
Web.Config :
我使用了标准模板,但未注释顶部(必须合并两个system.diagnostic部分以避免HTTP 500)
<system.diagnostics>
<sharedListeners>
<add name="AzureLocalStorage" type="WCFService.WebRole.AzureLocalStorageTraceListener, WCFService.WebRole" />
</sharedListeners>
<!--<sources>
<source name="System.ServiceModel" switchValue="Verbose, ActivityTracing">
<listeners>
<add name="AzureLocalStorage"/>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Verbose">
<listeners>
<add name="AzureLocalStorage"/>
</listeners>
</source>
</sources>-->
<trace autoflush="true">
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>