Created
May 8, 2017 21:33
-
-
Save solvingj/58160fb77e08237f840995dcc4015162 to your computer and use it in GitHub Desktop.
Simple Logger with Functional Influence
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
public class FunLog | |
{ | |
public List<Action<string>> InfoActions = new List<Action<string>>(); | |
public List<Action<string>> VerboseActions = new List<Action<string>>(); | |
public List<Action<string>> ErrorActions = new List<Action<string>>(); | |
public List<Action<string>> WarningActions = new List<Action<string>>(); | |
public List<Action<string>> TraceActions = new List<Action<string>>(); | |
[DebuggerStepThrough] | |
public FunLog(){ } | |
[DebuggerStepThrough] | |
public FunLog WithInfoAction(Action<string> action) | |
{ | |
InfoActions.Add(action); | |
return this; | |
} | |
[DebuggerStepThrough] | |
public FunLog WithVerboseAction(Action<string> action) | |
{ | |
VerboseActions.Add(action); | |
return this; | |
} | |
[DebuggerStepThrough] | |
public FunLog WithErrorAction(Action<string> action) | |
{ | |
ErrorActions.Add(action); | |
return this; | |
} | |
[DebuggerStepThrough] | |
public FunLog WithWarningAction(Action<string> action) | |
{ | |
WarningActions.Add(action); | |
return this; | |
} | |
[DebuggerStepThrough] | |
public FunLog WithTraceAction(Action<string> action) | |
{ | |
TraceActions.Add(action); | |
return this; | |
} | |
public void Info(string message) | |
{ | |
InfoActions.ForEach(action => action(message)); | |
} | |
public void Error(string message) | |
{ | |
ErrorActions.ForEach(action => action(message)); | |
} | |
public void Verbose(string message) | |
{ | |
VerboseActions.ForEach(action => action(message)); | |
} | |
public void Warning(string message) | |
{ | |
WarningActions.ForEach(action => action(message)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment