Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save solvingj/58160fb77e08237f840995dcc4015162 to your computer and use it in GitHub Desktop.
Save solvingj/58160fb77e08237f840995dcc4015162 to your computer and use it in GitHub Desktop.
Simple Logger with Functional Influence
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