我正在使用 azure表和NLog(NLog.Extensions.AzureTableStorage)编写SQL审核日志, 这是通过在实体框架中创建数据库拦截器来完成的,并且在大多数情况下都能正常工作,但是有时我收到了一个错误的请求,可以从应用程序见解中观察到。
下面是用于编写日志的代码
public class DBCommandInterceptor : DbCommandInterceptor
{
private readonly Logger _logger = LogManager.GetLogger("SQLAuditLog");
public override void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
HandleCommandExecuting(command);
}
public override void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
HandleCommandExecuting(command);
}
public override void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
{
HandleCommandExecuting(command);
}
private void HandleCommandExecuting(DbCommand command)
{
LogEventInfo eventLog = new LogEventInfo(LogLevel.Trace,_logger.Name, command.CommandText);
eventLog.Properties["Query"] = command.CommandText;
eventLog.Message = $"{ command.CommandText} ";
_logger.Log(eventLog);
}
}
错误请求错误的原因是什么?