1

SLAB SqlDatabaseSink 停止写入 Traces 表

我并行添加了一个 FlatFileSink 以确保侦听器不是问题,它可以很好地写入文件。我还有一个工作正常的 SqlDatabaseSink 单元测试,但是当通过 Global.asax 从主项目订阅时,只有 FlatFileSink 工作。截图如下。

根据@manikrish 的建议添加了 SLAB 内部事件侦听器(非常感谢),这是来自该日志的底层 SQLDatabaseSink 错误“无法加载文件或程序集'Newtonsoft.Json,版本 = 4.5.0.0,文化 = 中性, PublicKeyToken=30ad4fe6b2a6aeed'" - 详情如下,SLAB 内部日志。

接下来,我比较了主项目和单元测试项目(谁的 SQLDatabaseSink 工作)之间的 Newtonsoft.Json 的引用属性,两者都使用版本 6.0.8(我相信 WebApi 5.2.3 附带它),但注意到特定版本在后者。所以,我在主项目中做了同样的改变仍然没有运气

此外,主项目的 web.config 和单元测试项目的 app.config 也具有相同的程序集绑定:

  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
  </dependentAssembly>

接下来,我尝试通过更改 web.config、packages.config、csproj 中的引用属性来解决绑定重定向问题;基于其他stackoverflow问题(下面的链接)重新安装/更新Newtonsoft.Json以及调用程序集的(Microsoft.Practices.EnterpriseLibrary.SemanticLogging)NuGet包,仍然没有运气- SLAB内部日志中的相同绑定错误,没有证据我的投标重定向。

SLAB 内部日志:

Opcode : Info
Task : 65433
Version : 0
Payload : [message : System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
   at System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType, Boolean& coercedToDataFeed, Boolean& typeChanged, Boolean allowStreaming)
   at System.Data.SqlClient.SqlParameter.GetCoercedValue()
   at System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc)
   at System.Data.SqlClient.SqlCommand.SetUpRPCParameters(_SqlRPC rpc, Int32 startCount, Boolean inSchema, SqlParameterCollection parameters)
   at System.Data.SqlClient.SqlCommand.BuildRPC(Boolean inSchema, SqlParameterCollection parameters, _SqlRPC& rpc)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.BeginExecuteNonQueryInternal(AsyncCallback callback, Object stateObject, Int32 timeout, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.BeginExecuteNonQueryAsync(AsyncCallback callback, Object stateObject)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncImpl(Func`3 beginMethod, Func`2 endFunction, Action`1 endAction, Object state, TaskCreationOptions creationOptions)
   at System.Threading.Tasks.TaskFactory`1.FromAsync(Func`3 beginMethod, Func`2 endMethod, Object state)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQueryAsync(CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Sinks.SqlDatabaseSink.<>c__DisplayClass14.<<UseStoredProcedure>b__13>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Sinks.SqlDatabaseSink.<UseStoredProcedure>d__1d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Sinks.SqlDatabaseSink.<PublishEventsAsync>d__0.MoveNext()

=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
 (Fully-specified)
LOG: Appbase = file:///C:/work/StarLims/AMO/server/TFS/AMO/eyeNet/AI.eyeNet/
LOG: Initial PrivatePath = C:\work\StarLims\AMO\server\TFS\AMO\eyeNet\AI.eyeNet\bin
Calling assembly : Microsoft.Practices.EnterpriseLibrary.SemanticLogging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\work\StarLims\AMO\server\TFS\AMO\eyeNet\AI.eyeNet\web.config
LOG: Using host configuration file: C:\Users\siliodx\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/74a40fb9/3b0c98c/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/74a40fb9/3b0c98c/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/work/StarLims/AMO/server/TFS/AMO/eyeNet/AI.eyeNet/bin/Newtonsoft.Json.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
] 
EventName : DatabaseSinkPublishEventsFailedInfo
Timestamp : 2015-06-05T11:56:54.5518724Z
ProcessId : 6752
ThreadId : 12060

StackOverflow 支持链接:

臭名昭著的程序集绑定错误

无法加载文件或程序集“Newtonsoft.Json”或其依赖项之一。清单定义与程序集引用不匹配

使用多个项目时出现 Newtonsoft.Json.dll 问题

尽管有程序集重定向并加载了正确的版本,但程序集不匹配

截图: Global.asax SLAB 配置调用

平板配置

项目中的 NuGet SLAB 包

4

2 回答 2

3

语义日志记录应用程序块将内部事件记录到称为 SemanticLoggingEventSource 的预定义事件源。您可以创建一个额外的侦听器,将来自此事件源的事件记录到不同的接收器。

例如,下面的代码片段显示了如何将内部事件记录到文件中:

var slabInternalNotificationsListener = new ObservableEventListener();
slabInternalNotificationsListener.LogToFlatFile(@".\errors.txt");
slabInternalNotificationsListener.EnableEvents(SemanticLoggingEventSource.Log, System.Diagnostics.Tracing.EventLevel.Verbose, Keywords.All);

请查看 SemanticLoggingEventSource 中的日志以了解 SQL 接收器未记录事件的原因。

于 2015-06-04T19:33:24.203 回答
0

根本原因是web.config 中的一个程序集周围缺少dependentAssembly 标记

<dependentAssembly>
    <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>

非常感谢Mani和其他帮助我的SLAB 团队成员,特别是因为根本原因与他们的项目无关。

于 2015-06-19T11:37:10.243 回答