Skip to content

Instantly share code, notes, and snippets.

@jptoto
Created January 27, 2015 21:16
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 jptoto/9be57ce2fe253eb96739 to your computer and use it in GitHub Desktop.
Save jptoto/9be57ce2fe253eb96739 to your computer and use it in GitHub Desktop.
Custom Exception w/ Log4net
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using log4net;
namespace ConsoleApplication1
{
class Program
{
private static readonly ILog _log = LogManager.GetLogger(typeof(Program));
static void Main(string[] args)
{
_log.Error("kaboom!", new CustomException { SomeValue1 = "some value 1", SomeValue2 = "some value 2"});
}
}
public class CustomException : Exception
{
public CustomException()
: base() { }
public CustomException(string message)
: base(message) { }
public CustomException(string format, params object[] args)
: base(string.Format(format, args)) { }
public CustomException(string message, Exception innerException)
: base(message, innerException) { }
public CustomException(string format, Exception innerException, params object[] args)
: base(string.Format(format, args), innerException) { }
protected CustomException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
public string SomeValue1 { get; set; }
public string SomeValue2 { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment