gpt4 book ai didi

logging - 企业库6 LogCallHandler抛出异常 "The LogWriter has not been set for the Logger static class"

转载 作者:行者123 更新时间:2023-12-02 18:44:11 29 4
gpt4 key购买 nike

各位

我正在尝试使用 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>

此配置抛出异常:“尚未为 Logger 静态类设置 LogWriter。请通过调用 Logger.SetLogWriter 方法来设置它。”

我使用运行时配置找到了此问题的解决方案:

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)

但是,我正在通过配置文件使用配置。如何在配置文件中重现此行为?

谢谢!

最佳答案

企业库的提升行为在版本 6 中已更改。对静态 Logger 外观的影响是您需要设置内部 LogWriter(例如在应用程序启动时):更多详情请参阅https://entlib.codeplex.com/discussions/442089

谢谢

关于logging - 企业库6 LogCallHandler抛出异常 "The LogWriter has not been set for the Logger static class",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22558745/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com