'Code Review: Error logging after a given time period. How can I improve this code?
I wrote a little condition to only log ("trace" in example) SQL related errors after a period of 5 minutes from the first instance. I am always looking to make code more portable and better, so I'm opening up the forum for you guys to tell me how I can do this better, or if I'm handling it well.
//we will send another SQL alert only if 5 minutes have passed since the last SQL error
if (logType == TraceType.EROR & ex.InnerException.Source == ".Net SqlClient Data Provider" & _SQLErrAlertSent == false)
{
Trace(logType, sTraceMsg);
_SQLErrAlertSent = true;
_SqlExTimer = DateTime.UtcNow;
} else if (logType == TraceType.EROR & ex.InnerException.Source == ".Net SqlClient Data Provider" & _SQLErrAlertSent == true)
{
//we will send another SQL alert only if 5 minutes have passed since the last SQL error
DateTime dt = DateTime.UtcNow;
if ((dt - _SqlExTimer).TotalMinutes >= 5) {
Trace(logType, sTraceMsg);
_SqlExTimer = DateTime.UtcNow;
}
}
else
{
Trace(logType, sTraceMsg);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
