Microsoft.Practices.EnterpriseLibrary.Logging 4.0滚动日志切换致服务冻结求助
Enterprise Library Logging 4.0 午夜日志切换导致服务冻结
我正在使用Microsoft.Practices.EnterpriseLibrary.Logging 4.0版本,以下是Service.exe.config中的日志配置:
<configuration> <configSections> <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=23120fa21bb1ee49" /> </configSections> <loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="" logWarningsWhenNoCategoriesMatch="false"> <listeners> <add source="Enterprise Library Logging" formatter="Text Formatter" log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=23120fa21bb1ee49" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=23120fa21bb1ee49" name="Formatted EventLog TraceListener" /> <add enabled="true" formatter="Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.OutputDebugStringTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=23120fa21bb1ee49" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.OutputDebugStringTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=23120fa21bb1ee49" name="OutputDebugString TraceListener" /> <add fileName="Log\ShellServices.log" footer="" formatter="Text Formatter" header="" rollFileExistsBehavior="Increment" rollInterval="Midnight" rollSizeKB="0" maxArchiveFilesSizeKB="100000" timeStampPattern="yyyy-MM-dd" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=23120fa21bb1ee49" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=23120fa21bb1ee49" name="Rolling Flat File Trace Listener" /> </listeners> <formatters> <add template="{timestamp(local:yyyy-MM-dd HH:mm:ss.fff)} | {severity} ({priority}) | {category} | {message}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=23120fa21bb1ee49" name="Text Formatter" /> </formatters> <categorySources> <add switchValue="All" name="DebugView"> <listeners> <add name="OutputDebugString TraceListener" /> </listeners> </add> </categorySources> <specialSources> <allEvents switchValue="All" name="All Events"> <listeners> <add name="Rolling Flat File Trace Listener" /> </listeners> </allEvents> <errors switchValue="All" name="Logging Errors & Warnings"> <listeners> <add name="Formatted EventLog TraceListener" /> </listeners> </errors> </specialSources> </loggingConfiguration> </configuration>
目前遇到的问题:某客户所有服务器上,当Rolling Flat File Trace Listener在午夜触发日志切换时,下一条日志条目会导致服务冻结,必须通过任务管理器终止进程。已检查服务代码及Microsoft库代码(使用dotPeek反编译),未发现死锁或无限循环问题,求排查方向建议。
排查方向建议
- 文件系统相关问题
- 验证日志目录权限:确认服务运行账户对
Log\目录拥有完整的读写、重命名、删除权限,午夜切换时需要重命名旧日志文件,权限不足会导致进程阻塞。 - 排查文件锁定:使用Process Explorer等工具,在午夜切换时段检查是否有其他进程(如杀毒软件、备份工具)锁定了日志文件,导致EL无法完成文件操作而卡住。
- 验证日志目录权限:确认服务运行账户对
- EL 4.0版本已知缺陷
- Enterprise Library 4.0的RollingFlatFileTraceListener存在午夜切换的已知BUG,比如时区处理错误、文件重命名逻辑中的竞态条件,可尝试升级到5.0版本验证是否解决问题。
- 系统环境验证
- 检查服务器时区与系统时间:确保所有服务器时区一致且时间准确,错误的时区可能导致切换逻辑触发时机异常,引发阻塞。
- 磁盘空间检查:确认日志所在磁盘有足够剩余空间,磁盘满时文件操作会直接阻塞服务进程。
- 并发场景验证
- 观察午夜时段的日志写入并发量:如果服务在午夜有高并发日志写入,可能在文件切换时触发未被捕获的同步问题,可临时将切换时间改为凌晨1点,验证是否还会出现冻结。
- 进程转储分析
- 当服务冻结时,使用
procdump生成进程转储文件,通过WinDbg分析线程调用栈,准确定位阻塞的具体位置(如卡在文件IO、锁等待),这比静态反编译代码更能发现运行时问题。
- 当服务冻结时,使用
- 配置参数调整测试
- 临时修改
maxArchiveFilesSizeKB参数:EL 4.0中该参数的处理可能存在逻辑问题,尝试设置为0(不限制归档大小)或更小的值,观察是否还会触发冻结。
- 临时修改
内容的提问来源于stack exchange,提问作者RoadieRich
相关产品推荐
相关产品推荐

