TraceListener处理完全不相关的组件之间的错误

时间:2015-02-27 09:33:54

标签: c# .net logging owin system.data.sqlite

我将新的(NuGet)组件 Microsoft.AspNet.WebApi.OwinSelfHost 添加到现有的有效多线程应用程序中,该应用程序大量使用 System.Data.SQLite 的EntityFramework

现在完全不可预测的任何查询随机都可以通过callstack失败,这显示添​​加的 Owin 组件以某种方式集成到.NET的内部日志系统中(我个人既不理解也不使用(我使用) NLog 代替))使用Microsoft.Owin.Hosting.Tracing.DualWriter

System.Data.Entity.Core.EntityCommandExecutionException occurred
  HResult=-2146232004
  Message=An error occurred while executing the command definition. See the inner exception for details.
  Source=EntityFramework
  StackTrace:
       at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
       at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
       at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
       at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()
       at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
       at System.Data.Entity.Core.Objects.ObjectQuery`1.Execute(MergeOption mergeOption)
       at MyQueryExecution.SomeCode()
  InnerException: System.IO.IOException
       HResult=-2147024890
       Message=The handle is invalid.

       Source=mscorlib
       StackTrace:
            at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
            at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
            at System.IO.TextWriter.SyncTextWriter.Write(Char[] buffer, Int32 index, Int32 count)
            at Microsoft.Owin.Hosting.Tracing.DualWriter.Write(Char[] buffer, Int32 index, Int32 count)
            at System.Diagnostics.TextWriterTraceListener.WriteLine(String message)
            at System.Diagnostics.TraceInternal.WriteLine(String message)
            at System.Data.SQLite.SQLiteLog.LogCallback(IntPtr pUserData, Int32 errorCode, IntPtr pMessage)
            at System.Data.SQLite.UnsafeNativeMethods.sqlite3_prepare_interop(IntPtr db, IntPtr pSql, Int32 nBytes, IntPtr& stmt, IntPtr& ptrRemain, Int32& nRemain)
            at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String& strRemain)
            at System.Data.SQLite.SQLiteCommand.BuildNextCommand()
            at System.Data.SQLite.SQLiteDataReader.NextResult()
            at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
            at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
            at System.Data.SQLite.SQLiteCommand.ExecuteDbDataReader(CommandBehavior behavior)
            at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
            at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
            at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
       InnerException: 

我已经尝试禁用SQLite端的日志记录:

System.Data.SQLite.SQLiteLog.Enabled = false;

和Owin:

appBuilder.Properties.Remove("host.TraceOutput");
appBuilder.Properties.Remove("host.TraceSource");
appBuilder.Properties.Remove("server.LoggerFactory");

但没有成功/改变。

0 个答案:

没有答案