Skip to content

Instantly share code, notes, and snippets.

@btompkins
Last active December 11, 2015 18:58
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 btompkins/4645265 to your computer and use it in GitHub Desktop.
Save btompkins/4645265 to your computer and use it in GitHub Desktop.
using Ducksboard;
using Ducksboard.Objects;
using log4net.Appender;
using log4net.Core;
namespace Logging.DucksboardLog4NetLogger
{
public class DucksboardAppender : AppenderSkeleton
{
private static DucksboardClient _ducksboardClient;
public string ApiKey { get; set; }
public string WidgetId { get; set; }
protected override void Append(LoggingEvent loggingEvent)
{
if (_ducksboardClient == null)
_ducksboardClient = new DucksboardClient(ApiKey);
var timeline = new Timeline
{
Value =
{
Image = GetImage(loggingEvent.Level),
Content = loggingEvent.RenderedMessage,
Title = loggingEvent.Level.ToString()
}
};
_ducksboardClient.Update(WidgetId, timeline);
}
private static string GetImage(Level level)
{
if (level >= Level.Error)
return
"https://app.ducksboard.com/static/img/timeline/red.gif";
return level == Level.Warn ?
"https://app.ducksboard.com/static/img/timeline/orange.gif" :
"https://app.ducksboard.com/static/img/timeline/green.gif";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment