Skip to content

Instantly share code, notes, and snippets.

@SimonCropp
Created December 5, 2012 10:04
Show Gist options
  • Save SimonCropp/4214439 to your computer and use it in GitHub Desktop.
Save SimonCropp/4214439 to your computer and use it in GitHub Desktop.
LogParamsOnException
Before
public class SimpleClass
{
[LogToDebugOnException]
void Method1(string param1, int param2)
{
//Do Stuff
}
[LogToTraceOnException]
void Method2(string param1, int param2)
{
//Do Stuff
}
}
After IL Weaving
public class SimpleClass
{
static Logger logger;
static SimpleClass()
{
logger = LogManager.GetCurrentClassLogger();
}
void Method1(string param1, int param2)
{
try
{
//Do Stuff
}
catch (Exception exception)
{
if (logger.IsDebugEnabled)
{
var message = string.Format("Exception occurred in SimpleClass.Method1. param1 '{0}', param2 '{1}'", param1, param2);
logger.DebugException(message, exception);
}
throw;
}
}
void Method2(string param1, int param2)
{
try
{
//Do Stuff
}
catch (Exception exception)
{
if (logger.IsTraceEnabled)
{
var message = string.Format("Exception occurred in SimpleClass.Method2. param1 '{0}', param2 '{1}'", param1, param2);
logger.TraceException(message, exception);
}
throw;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment