C#.NET Suppress Trace Messages From Specific "noisy" DLL
/// <summary>
/// Provides the ability to log diagnostics information to the system
trace log.
/// </summary>
public class DiagnosticsSupport
/// <summary>
/// Writes the specified message to the diagnostics trace log./// </summary>
/// <param name="message">The message to be written to the log.</param>
/// <param name="includeTimeStamp">Determines if the message should be written with a timestamp, by default this is true.</param>
public static void Log(String message, bool includeTimeStamp)
{
message = StringSupport.CleanString(message);
String longTimeString = String.Format("{0:HH:mm:ss}", DateTime.Now);
String timedMesssage = String.Format("{0} {1}.{2}: {3}", DateTime.Now.ToShortDateString(), longTimeString, DateTime.Now.Millisecond, message)
Trace.WriteLine(includeTimeStamp ? timedMesssage : message, "8aaa0a9a-8094-4cc6-af98-e3216a39d3bb");
Console.WriteLine(message);
}
}
using System.Diagnostics;
using System.IO;
namespace CENTREL.XIA.Support
{
/// <summary>
/// Represents an advanced text writer trace listener.
/// </summary>
public class AdvancedTextWriterTraceListener:
TextWriterTraceListener
{
/// <summary>
/// Initializes a new instance of the
CENTREL.XIA.Support.AdvancedTextWriterTraceListener class.
/// </summary>
public AdvancedTextWriterTraceListener()
{
}
/// <summary>
/// Initializes a new instance of the
CENTREL.XIA.Support.AdvancedTextWriterTraceListener class using the specified
writer as recipient of the tracing or debugging output.
/// <param name="writer">A System.IO.TextWriter that receives the output from the System.Diagnostics.TextWriterTraceListener.</param>
public AdvancedTextWriterTraceListener(TextWriter writer):
base(writer)
{
}
/// <summary>
/// Writes a message to the listener when the category matches the
well known GUIDB "8aaa0a9a-8094-4cc6-af98-e3216a39d3bb". Only the
message is written, the category is ignored.
/// </summary>
/// <param name="message">The message to write to the listener.</param>
/// <param name="category">The category name or well known GUID
"8aaa0a9a-8094-4cc6-af98-e3216a39d3bb".</param>
public override void
WriteLine(string message, string category)
{
if (!StringSupport.Equals(category, "8aaa0a9a-8094-4cc6-af98-e3216a39d3bb")) { return; }
base.WriteLine(message);
}
}
}
Comments
Post a Comment