Created
May 19, 2015 01:30
-
-
Save Benrnz/3e645fc2dcc1da94b9ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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