Last active
December 11, 2015 18:58
-
-
Save btompkins/4645265 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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