Skip to content

Instantly share code, notes, and snippets.

@DavidRogersDev
Last active May 22, 2018 06:21
Show Gist options
  • Save DavidRogersDev/f9207ee4eebbc01df958 to your computer and use it in GitHub Desktop.
Save DavidRogersDev/f9207ee4eebbc01df958 to your computer and use it in GitHub Desktop.
An excellent tracing class pulled from Brock Allen's supremely cool MembershipReboot project. Just replace the name of the trace-source on line 82 from MembershipReboot appropriately.
/*
* Copyright (c) Brock Allen. All rights reserved.
* see license.txt
*/
using System;
using System.Diagnostics;
namespace BrockAllen.MembershipReboot
{
static public class Tracing
{
[DebuggerStepThrough]
public static void Start(string message)
{
TraceEvent(TraceEventType.Start, message, false);
}
[DebuggerStepThrough]
public static void Start(string message, params object[] args)
{
Start(String.Format(message, args));
}
[DebuggerStepThrough]
public static void Stop(string message)
{
TraceEvent(TraceEventType.Stop, message, false);
}
[DebuggerStepThrough]
public static void Stop(string message, params object[] args)
{
Stop(String.Format(message, args));
}
[DebuggerStepThrough]
public static void Verbose(string message)
{
TraceEvent(TraceEventType.Verbose, message, false);
}
[DebuggerStepThrough]
public static void Verbose(string message, params object[] args)
{
Verbose(String.Format(message, args));
}
[DebuggerStepThrough]
public static void Information(string message)
{
TraceEvent(TraceEventType.Information, message, false);
}
[DebuggerStepThrough]
public static void Information(string message, params object[] args)
{
Information(String.Format(message, args));
}
[DebuggerStepThrough]
public static void Warning(string message)
{
TraceEvent(TraceEventType.Warning, message, false);
}
[DebuggerStepThrough]
public static void Warning(string message, params object[] args)
{
Warning(String.Format(message, args));
}
[DebuggerStepThrough]
public static void Error(string message)
{
TraceEvent(TraceEventType.Error, message, false);
}
[DebuggerStepThrough]
public static void Error(string message, params object[] args)
{
Error(String.Format(message, args));
}
[DebuggerStepThrough]
public static void TraceEvent(TraceEventType type, string message, bool suppressTraceService)
{
TraceSource ts = new TraceSource("MembershipReboot");
if (Trace.CorrelationManager.ActivityId == Guid.Empty)
{
if (type != TraceEventType.Verbose)
{
Trace.CorrelationManager.ActivityId = Guid.NewGuid();
}
}
ts.TraceEvent(type, 0, message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment