Microsoft Enterprise Library 5.0 日志记录仅发生在前几个 WCF 方法调用上
我在使用 Enterprise Library 5.0 日志记录时遇到不稳定的日志记录。
问题出在 IIS (7.5) 中托管的 WCF 4.0 应用程序,该应用程序在负载平衡配置的 Windows 2008 R2 服务器上运行。我正在使用 Unity (2.0) 进行依赖注入。我已将库配置为记录到滚动文本文件。该应用程序使用AppFabricCache。
重新启动托管服务的 Web 应用程序后,日志记录似乎在前几次调用中成功。此后,没有看到进一步的记录。 我要么在配置中犯了错误,要么在将输出写入/刷新到文本文件时可能存在一些争用。我知道 Logging 类以线程安全的方式运行。
以下是配置文件的相关部分。 任何想法表示赞赏。谢谢。
<loggingConfiguration name="loggingConfiguration" tracingEnabled="true" defaultCategory="General">
<listeners>
<add name="Rolling File Trace Listener"
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="d:\SOMEPATH\Logs\trace.log"
formatter="Text Formatter"
header="" footer=""
timeStampPattern="yyyy-MM-dd hh:mm:ss.fff"
traceOutputOptions="None"
maxArchivedFiles="2000"
rollFileExistsBehavior="Increment" rollInterval="Day" rollSizeKB="1024" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="{timestamp(yyyyMMdd HH:mm:ss.fff)} - {message}"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Rolling File Trace Listener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Rolling File Trace Listener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
I am experiencing erratic logging when using Enterprise Library 5.0 Logging.
The issue is with a WCF 4.0 application hosted in IIS (7.5) running on Windows 2008 R2 Servers in a load balanced configuration. I am using Unity (2.0) for Dependency Injection. I have configured the library to log to rolling text file. The application uses AppFabricCache.
It seems that the logging succeeds in the first few calls following restart of the Web application hosting the service. Thereafter, no further logging is seen.
I have either made an error in the configuration or there might be some contention in writing / flushing output to the text file. I understand that the Logging class operates in a thread safe way.
Below is the relevant part of the config file.
Any thoughts appreciated. Thanks.
<loggingConfiguration name="loggingConfiguration" tracingEnabled="true" defaultCategory="General">
<listeners>
<add name="Rolling File Trace Listener"
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="d:\SOMEPATH\Logs\trace.log"
formatter="Text Formatter"
header="" footer=""
timeStampPattern="yyyy-MM-dd hh:mm:ss.fff"
traceOutputOptions="None"
maxArchivedFiles="2000"
rollFileExistsBehavior="Increment" rollInterval="Day" rollSizeKB="1024" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="{timestamp(yyyyMMdd HH:mm:ss.fff)} - {message}"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Rolling File Trace Listener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Rolling File Trace Listener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该做的一件事是更改
errors
specialSource
以不使用滚动文件跟踪侦听器。它应该使用另一个侦听器,例如FlatFileTraceListener
或EventLogTraceListener
。我对发生的情况的猜测是写入日志条目时发生错误(可能是试图滚动的权限问题)。但是您在日志中看不到任何内容,因为错误源设置为使用刚刚失败的相同侦听器,因此错误记录也会失败。
One thing you should do is change the
errors
specialSource
to not use the Rolling File Trace Listener. It should use another listener such asFlatFileTraceListener
orEventLogTraceListener
.My guess as to what is going on is that an error is occurring writing your log entry (perhaps a permission problem trying to roll). But you don't see anything in the logs because the errors source is set to use the same listener that just failed so the logging of the error also fails.
感谢 Turzo,我重新配置为将错误记录到平面文件中。然后我就可以看到错误消息的详细信息。部分错误消息被拒绝访问。部分与找不到文件路径/格式不正确有关。事实证明,TimeStampPattern 指定不正确,因为它没有生成可接受的文件名格式。我将其更改为: timeStampPattern="yyyyMMdd_hhmm" 现在已生成滚动文件。
Thanks to Turzo, I reconfigured to log errors to Flat File. I was then able to see error message detail. Part of the error message was access denied. Part of it related to file path not found / incorrect format. It turns out that the TimeStampPattern was incorrectly specified as it does not generate an accepted file name format. I changed it to: timeStampPattern="yyyyMMdd_hhmm" and now have rolling files generated.