Skip to content

Instantly share code, notes, and snippets.

@markholdt
Created February 1, 2016 05:40
Show Gist options
  • Save markholdt/50e9ef90a805161db39d to your computer and use it in GitHub Desktop.
Save markholdt/50e9ef90a805161db39d to your computer and use it in GitHub Desktop.
Logging to Slack with Servicestack & ILog
public class SlackLogger : ILog
{
public string incomingWebHookUrl { get; set; }
public SlackLogger(string incomingWebHookUrl)
{
this.incomingWebHookUrl = incomingWebHookUrl;
}
public void Info(object message)
{
this.incomingWebHookUrl.PostJsonToUrl(new { text = "INFO:" + message.ToString() });
}
public void Info(object message, Exception exception)
{
this.incomingWebHookUrl.PostJsonToUrl(new { text = "INFO:" + message.ToString() + Environment.NewLine + " StackTrace:" + Environment.NewLine + exception.StackTrace });
}
public void Debug(object message)
{
this.incomingWebHookUrl.PostJsonToUrl(new { text = "Debug:" + message.ToString() });
}
public void Debug(object message, Exception exception)
{
this.incomingWebHookUrl.PostJsonToUrl(new { text = "Debug:" + message.ToString() + Environment.NewLine + " StackTrace:" + Environment.NewLine + exception.StackTrace });
}
public void DebugFormat(string format, params object[] args)
{
throw new NotImplementedException();
}
public void Error(object message)
{
this.incomingWebHookUrl.PostJsonToUrl(new { text = "Error:" + message.ToString() });
}
public void Error(object message, Exception exception)
{
this.incomingWebHookUrl.PostJsonToUrl(new { text = "Error:" + message.ToString() + Environment.NewLine + " StackTrace:" + Environment.NewLine + exception.StackTrace });
}
public void ErrorFormat(string format, params object[] args)
{
throw new NotImplementedException();
}
public void Fatal(object message)
{
this.incomingWebHookUrl.PostJsonToUrl(new
{
text = "Fatal:" + message.ToString()
});
}
public void Fatal(object message, Exception exception)
{
this.incomingWebHookUrl.PostJsonToUrl(new
{
text = "Fatal:" + message.ToString() + Environment.NewLine + " StackTrace:" + Environment.NewLine + exception.StackTrace
});
}
public void FatalFormat(string format, params object[] args)
{
throw new NotImplementedException();
}
public void InfoFormat(string format, params object[] args)
{
throw new NotImplementedException();
}
public void Warn(object message)
{
this.incomingWebHookUrl.PostJsonToUrl(new
{
text = "Warn:" + message.ToString()
});
}
public void Warn(object message, Exception exception)
{
this.incomingWebHookUrl.PostJsonToUrl(new
{
text = "Warn:" + message.ToString() + Environment.NewLine + " StackTrace:" + Environment.NewLine + exception.StackTrace
});
}
public void WarnFormat(string format, params object[] args)
{
throw new NotImplementedException();
}
public bool IsDebugEnabled { get; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment