操作可能会破坏运行时企业库6的稳定性

时间:2013-08-28 04:11:11

标签: .net logging enterprise-library verificationexception

我创建了一个.NET 4.5控制台应用程序来尝试新的Ent Lib v6中的语义记录位。 使用PDF中的示例代码:

var listener2 = new ObservableEventListener();
listener2.EnableEvents( EventSourceCore.Log , EventLevel.LogAlways , Keywords.All );
SinkSubscription<SqlDatabaseSink> subscription = listener2.LogToSqlDatabase( "Demo Semantic Logging Instance" , ConfigurationManager.AppSettings["mdbconn"] );

立即运行代码会出现错误“操作可能会破坏运行时的稳定性”。查看VS2012中Exception帮助器中的堆栈跟踪,我看到了

  at Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy`1..ctor(Int32 retryCount, TimeSpan minBackoff, TimeSpan maxBackoff, TimeSpan deltaBackoff)
   at Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Sinks.SqlDatabaseSink..ctor(String instanceName, String connectionString, String tableName, TimeSpan bufferingInterval, Int32 bufferingCount, Int32 maxBufferSize, TimeSpan onCompletedTimeout)
   at Microsoft.Practices.EnterpriseLibrary.SemanticLogging.SqlDatabaseLog.LogToSqlDatabase(IObservable`1 eventStream, String instanceName, String connectionString, String tableName, Nullable`1 bufferingInterval, Int32 bufferingCount, Nullable`1 onCompletedTimeout, Int32 maxBufferSize)
   at svc2.Program.LogPrep() in c:\cos\Program.cs:line 66
   at svc2.Program.Main(String[] args) in c:\cos\Program.cs:line 23
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

查看Entlib源代码,SqlDatabaseSink.cs中的第32行显示

 private readonly RetryPolicy retryPolicy = new RetryPolicy<SqlDatabaseTransientErrorDetectionStrategy>(5, TimeSpan.FromSeconds(1), TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(5));

转到显示

的RetryPolicyGeneric.cs中的第59行
 public RetryPolicy(int retryCount, TimeSpan minBackoff, TimeSpan maxBackoff, TimeSpan deltaBackoff)
            : base(new T(), retryCount, minBackoff, maxBackoff, deltaBackoff)

但是我没有看到任何可能导致问题的隐式演员,这在其他SO帖子中找到。

我错过了什么?有没有人真正看到过记录块工作“开箱即用”?

谢谢,

1 个答案:

答案 0 :(得分:5)

问题出在核心MS库中。

http://support.microsoft.com/kb/2748645

包含问题的补丁。我在那个上烧了好几个小时。希望下一个尝试这个的人不会失去相同的时间。