Skip to content

Instantly share code, notes, and snippets.

@MoaidHathot
Created December 25, 2016 23:04
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 MoaidHathot/bd34e1095908246d299abfbb135e0997 to your computer and use it in GitHub Desktop.
Save MoaidHathot/bd34e1095908246d299abfbb135e0997 to your computer and use it in GitHub Desktop.
//For testing purposes...throws exception once per <ThrowExceptionForCount>
public class ExceptionThrowerAppender : ConsoleAppender
{
public int ThrowExceptionForCount { get; set; } = 1;
private int _count;
public ExceptionThrowerAppender()
{
ErrorHandler = new PropogateErrorHandler();
}
protected override void Append(LoggingEvent loggingEvent)
{
if (0 == System.Threading.Interlocked.Increment(ref _count) % ThrowExceptionForCount)
{
throw new Exception($"Interval {ThrowExceptionForCount} is reached with counter {_count}");
}
base.Append(loggingEvent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment