Skip to content

Instantly share code, notes, and snippets.

Last active June 7, 2017 07:38
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Raygun4Net automatic Breadcrumb logging with log4net
<section name="RaygunSettings" type="Mindscape.Raygun4Net.RaygunSettings, Mindscape.Raygun4Net" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
<RaygunSettings apikey="[YOUR-API-KEY-HERE]" breadcrumbsLevel="Debug" />
<appender name="breadcrumbAppender" type="Raygun.Examples.RaygunBreadcrumbAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
<root name="RaygunApp">
<level value="DEBUG" />
<appender-ref ref="breadcrumbAppender" />
using log4net.Appender;
using log4net.Core;
using Mindscape.Raygun4Net;
using Mindscape.Raygun4Net.Breadcrumbs;
namespace Raygun.Examples
public class RaygunBreadcrumbAppender : AppenderSkeleton
protected override void Append(LoggingEvent loggingEvent)
var crumb = new RaygunBreadcrumb();
int lineNumber;
if (int.TryParse(loggingEvent.LocationInformation.LineNumber, out lineNumber))
crumb.LineNumber = lineNumber;
crumb.Message = RenderLoggingEvent(loggingEvent);
crumb.ClassName = loggingEvent.LocationInformation.ClassName;
crumb.MethodName = loggingEvent.LocationInformation.MethodName;
crumb.CustomData.Add("Thread", loggingEvent.ThreadName);
if (loggingEvent.Properties != null)
foreach (var propertyKey in loggingEvent.Properties.GetKeys())
crumb.CustomData.Add(propertyKey, loggingEvent.Properties[propertyKey]);
switch (loggingEvent.Level.Name)
case "ALL":
case "DEBUG":
crumb.Level = RaygunBreadcrumbLevel.Debug;
case "INFO":
crumb.Level = RaygunBreadcrumbLevel.Info;
case "WARN":
crumb.Level = RaygunBreadcrumbLevel.Warning;
case "FATAL":
case "ERROR":
crumb.Level = RaygunBreadcrumbLevel.Error;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment