我有一个Azure工作角色,我配置了一个log4net Trace Appender来写入WindowsAzure.Diagnostics。这是通过在工作角色的RoleEntryPoint中进行以下调用来完成的。
using System;
using Microsoft.WindowsAzure.Diagnostics;
using log4net.Config;
namespace XXX
{
public class WorkerRole : RoleEntryPoint
{
public override bool OnStart()
{
var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Warning;
config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(5);
config.WindowsEventLog.DataSources.Add("System!*");
config.WindowsEventLog.DataSources.Add("Application!*");
config.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Error;
config.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromMinutes(5);
DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config);
XmlConfigurator.Configure();
}
}
}
App.config文件的配置方式如下:
<log4net>
<appender name="TraceAppender" type="log4net.Appender.TraceAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%logger - %message" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="TraceAppender" />
</root>
</log4net>
<system.diagnostics>
<trace>
<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>
这将导致所有消息(即使是错误消息)以“详细”级别记录在表存储中。如何修复?