|
private void Executed(DbCommand command, DbCommandInterceptionContext interceptionContext)
{ var timer = (Stopwatch)interceptionContext.UserState;
timer.Stop(); if (interceptionContext.Exception != null)
{
File.AppendAllLines(
_logFile, new string[]
{ "错误SQL语句",
interceptionContext.Exception.Message,
command.CommandText,
Environment.StackTrace, string.Empty, string.Empty,
});
} else if (timer.ElapsedMilliseconds >= _executionTime)
{
File.AppendAllLines(
_logFile, new string[]
{ string.Format("耗时SQL语句({0}ms)",timer.ElapsedMilliseconds),
command.CommandText,
Environment.StackTrace, string.Empty, string.Empty,
});
}
}
|
|
|