Skip to content

Instantly share code, notes, and snippets.

@Benrnz
Created May 19, 2015 01:30
Show Gist options
  • Save Benrnz/3e645fc2dcc1da94b9ff to your computer and use it in GitHub Desktop.
Save Benrnz/3e645fc2dcc1da94b9ff to your computer and use it in GitHub Desktop.
App.Config
<system.diagnostics>
<switches>
<add name="TraceLoggerOn" value="0" />
</switches>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="D:\Logs\TraceLogger.log" traceOutputOptions="DateTime, ThreadId" >
<filter type="System.Diagnostics.EventTypeFilter" initializeData="Information" />
</add>
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
using System;
using System.Diagnostics;
public static class TraceLogger
{
public static void LogInformation(Func<string> getMessage)
{
if (new BooleanSwitch("TraceLoggerOn", string.Empty).Enabled)
{
Trace.TraceInformation(getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment