如何从WAD日志中抑制azure缓存客户端警告

时间:2013-05-08 14:53:47

标签: caching azure azure-caching

我们有2个角色使用缓存角色来共享数据。部署时,我们会在日志中获得许多以下条目:

INFORMATION: <CASClient> Updated partition table to (1-901) generation: 635036190744461419:0 with transfer (1-901) generation: 635036190744461419:0; TraceSource 'w3wp.exe' event

INFORMATION: <Complaint> Add hard complaint :0 ; TraceSource 'w3wp.exe' event

更改设置值:

<Setting name="Microsoft.WindowsAzure.Plugins.Caching.ClientDiagnosticLevel" value="0" />

似乎没有效果。

我们如何从WADLogs表中删除这些噪音?

4 个答案:

答案 0 :(得分:4)

似乎缓存中存在错误(请参阅此post)。我试图摆脱这些日志条目,运行SDK1.8没有运气。最近我切换到了SDK2.0,但不幸的是问题仍然没有解决。

Bug report on GitHub

答案 1 :(得分:1)

我将为此添加一个过滤器。

web.config的示例:

<system.diagnostics>
    <trace>
        <listeners>
            <add name="console" type="System.Diagnostics.ConsoleTraceListener">
                <filter type="Namespace.TraceFilter, Assembly" initializeData="Information"/>
            </add>
        </listeners>
    </trace>
</system.diagnostics>

注意:属性initializeData设置为System.Diagnostics.SourceLevels枚举的文本。请参阅here

<强> TraceFilter.cs

public class TraceFilter : EventTypeFilter
{
    public TraceFilter(SourceLevels level)
        : base(level) {}

    public override bool ShouldTrace(TraceEventCache cache, string source, TraceEventType eventType, int id, string formatOrMessage, object[] args, object data1, object[] data)
    {
        return !Regex.IsMatch(formatOrMessage, "INFORMATION: <[^>*]*>");
    }
}

您可以将其扩展为更通用的过滤器,该过滤器可以运行接受不同模式的配置以包含/忽略。

答案 2 :(得分:1)

this thread on GitHub结束阅读建议后,我们设法通过在应用程序中运行以下代码来禁用此功能:

DataCacheClientLogManager.ChangeLogLevel(TraceLevel.Off);
DataCacheClientLogManager.SetSink(DataCacheTraceSink.DiagnosticSink, TraceLevel.Off);

这将停止从Azure缓存客户端进行所有日志记录,而无需关闭自己的WarningInformation级别日志。

我们最终在DataCacheClient周围的Cache Provider包装器的构造函数中添加了这个:

public class AzureCacheProvider : ICacheProvider
{
    public AzureCacheProvider()
    {
        DataCacheClientLogManager.ChangeLogLevel(TraceLevel.Off);

        DataCacheClientLogManager.SetSink(
            DataCacheTraceSink.DiagnosticSink, 
            TraceLevel.Off);

        InitializeCache();
    }

答案 3 :(得分:1)

这是一个完整的解决方案

确保使用您的命名空间和相应的程序集名称。

using Microsoft.WindowsAzure.Diagnostics;
using System.Diagnostics;
using System.Text.RegularExpressions;

namespace MyNamespace
{
    /*
     Solves the Azure In-Role Cache client warnings bug which is too verbose in the WAD logs
     Also Solves Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener not using Filter

     For roles which uses in-role caching, configure your Web.config or app.config with the following system.diagnostics listner and filter:
    <system.diagnostics>
        <trace>
            <listeners>
                <add name="AzureDiagnostics" type="MyNamespace.FilteringDiagnosticMonitorTraceListener, MyAssemblyName">
                <!-- WARNING: does not work with type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                              because the DiagnosticMonitorTraceListener does not call the filter's ShouldTrace method as is was supposed to... -->
                <!-- Note:    working with type="System.Diagnostics.ConsoleTraceListener" -->

                    <filter type="MyNamespace.SuppressCacheClientWarningsTraceFilter, MyAssemblyName" initializeData="Information"/>
                    <!-- Note: The attribute initializeData is set to the text from System.Diagnostics.SourceLevels enum. -->
                </add>
            </listeners>
        </trace>
    </system.diagnostics>
     */

    /// <summary>EventTypeFilter which suppress the 'noise' messages from the In-Role Azure Cache client
    /// </summary>
    /// <remarks>It's a workaround for the following problem http://social.msdn.microsoft.com/Forums/windowsazure/en-US/7ebbc44e-7b61-4bbe-aa54-a85a7788079f/complaint-add-hard-complaint?forum=windowsazuredata.
    /// The solution is based on http://stackoverflow.com/questions/16443856/how-to-suppress-azure-cache-client-warnings-from-the-wad-logs and http://pastebin.com/qKc1aTTW
    /// </remarks>
    public class SuppressCacheClientWarningsTraceFilter : EventTypeFilter
    {

        public SuppressCacheClientWarningsTraceFilter(SourceLevels level)
            : base(level) { }

        public override bool ShouldTrace(TraceEventCache cache, string source, TraceEventType eventType, int id, string formatOrMessage, object[] args, object data1, object[] data)
        {
            return !(
                        (eventType == TraceEventType.Information && Regex.IsMatch(formatOrMessage, @"^INFORMATION:\ <(CASClient|Complaint)>"))
                        || (eventType == TraceEventType.Warning && Regex.IsMatch(formatOrMessage, @"^WARNING:\ <SimpleSendReceiveModule>\ DeadServerCallback"))
                    );
            //return !Regex.IsMatch(formatOrMessage, @"^INFORMATION: <[^>*]*>");
        }
    }

    /// <summary>Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener which uses the configured Trace Filter
    /// </summary>
    /// <remarks>It's a workaround for the following problem http://social.msdn.microsoft.com/Forums/en-US/92ed1175-d6b7-4173-a224-0f7eb3e99481/diagnosticmonitortracelistener-ignors-filter?forum=windowsazuretroubleshooting
    /// The solution is based on the thread comment from "Qin Dian Tang - MSFT": "If you need to use trace filter, then it is needed to use a custom trace listener which derives from DiagnosticMonitorTraceListener, override TraceData, and either manually check filters or call the root class's (TraceListener) TraceData."
    /// </remarks>
    public class FilteringDiagnosticMonitorTraceListener : DiagnosticMonitorTraceListener
    {
        public FilteringDiagnosticMonitorTraceListener() : base() { }

        public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
        {
            if (this.Filter == null || this.Filter.ShouldTrace(eventCache, source, eventType, id, format, args, null, null))
                base.TraceEvent(eventCache, source, eventType, id, format, args);
        }

        public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
        {
            if (this.Filter == null || this.Filter.ShouldTrace(eventCache, source, eventType, id, message, null, null, null))
                base.TraceEvent(eventCache, source, eventType, id, message);
        }
    }
}

希望它有所帮助。