专家
我尝试将LogCallHandler用于拦截,如下所示:
<interception>
<policy name="policyLogCallHandler">
<matchingRule name="LogsMachingRule" type="NamespaceMatchingRule">
<constructor>
<param name="namespaceName" value="NetTcpContracts" />
</constructor>
</matchingRule>
<callHandler type="Microsoft.Practices.EnterpriseLibrary.Logging.PolicyInjection.LogCallHandler, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="callHandlerLog">
<constructor>
<param name="eventId" value="9002"/>
<param name="logBeforeCall" value="true"/>
<param name="logAfterCall" value="true"/>
<param name="beforeMessage" value="--- begin"/>
<param name="afterMessage" value="--- end"/>
<param name="includeParameters" value="true"/>
<param name="includeCallStack" value="true"/>
<param name="includeCallTime" value="true"/>
<param name="priority" value="1"/>
<param name="order" value="1"/>
</constructor>
</callHandler>
</policy>
</interception>
此配置引发异常:&#34;尚未为Logger静态类设置LogWriter。设置它调用Logger.SetLogWriter方法。&#34;
我使用运行时配置找到了解决此问题的方法:
IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
LogWriterFactory logWriterFactory = new LogWriterFactory(configurationSource);
Logger.SetLogWriter(logWriterFactory.Create());
LogEntry entry = new LogEntry();
entry.Message = "I am logging";
Logger.Write(entry)
但是,我通过配置文件使用配置。如何在配置文件中重现此行为?
韩国社交协会!
答案 0 :(得分:5)
Enterprise Library的boostrapping行为在版本6中发生了变化。静态Logger外观的影响是您需要设置内部LogWriter(例如在应用程序启动时): 有关详细信息,请参阅https://entlib.codeplex.com/discussions/442089
由于
答案 1 :(得分:0)
今天遇到了同样的错误,我刚刚删除了最新版本的EL日志记录块,并使用nuget包管理器安装了5.0.505.1 version,并且它有效。