Created
December 5, 2012 10:04
-
-
Save SimonCropp/4214439 to your computer and use it in GitHub Desktop.
LogParamsOnException
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
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