我创建了一个 .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 的异常帮助程序中的堆栈跟踪,我看到
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 帖子中发现的。
我错过了什么?有没有人真正看到日志块“开箱即用”?
谢谢,