.net 当文件不可访问时,Enterprise Library Logging 4.1不会写入错误侦听器
我们已经设置了Enterprise Library 4.1日志记录,以便在常规日志记录失败时写入事件日志。当日志记录配置不正确时(例如,侦听器文件名属性中的无效字符),这可以正常工作,但当配置的文件由于权限无效而无法写入时,不会将任何内容写入事件日志 FWIW以下是配置文件:.net 当文件不可访问时,Enterprise Library Logging 4.1不会写入错误侦听器,.net,logging,enterprise-library,.net,Logging,Enterprise Library,我们已经设置了Enterprise Library 4.1日志记录,以便在常规日志记录失败时写入事件日志。当日志记录配置不正确时(例如,侦听器文件名属性中的无效字符),这可以正常工作,但当配置的文件由于权限无效而无法写入时,不会将任何内容写入事件日志 FWIW以下是配置文件: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section na
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
<loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add source="Enterprise Library Logging" formatter="Event Log Formatter" machineName="."
log="Application"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
traceOutputOptions="None" filter="All"
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Formatted EventLog TraceListener" />
<add formatter="Text Formatter"
fileName="d:\trace.log" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Text TraceListener" />
</listeners>
<formatters>
<add template="Timestamp: {timestamp}
Message: {message}
Category: {category}
Priority: {priority}
EventId: {eventid}
Severity: {severity}
Title:{title}
Machine: {machine}
Application Domain: {appDomain}
Process Id: {processId}
Process Name: {processName}
Win32 Thread Id: {win32ThreadId}
Thread Name: {threadName}
Extended Properties: {dictionary({key} - {value}
)}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Event Log Formatter" />
<add template="[{timestamp(yyyy-MM-dd HH:mm:ss,fff)}] {severity} {category}: {message}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Text Formatter" />
</formatters>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category">
<listeners>
<add name="Text TraceListener" />
</listeners>
</notProcessed>
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
</configuration>
有人解决了这个问题吗?您提到,当出现有关无效权限的问题时,您会看到这种行为;虽然没有关于此的任何特定文档,但有关于文件读/写访问的信息: 问题似乎是企业库不考虑无法写入日志文件,因为它只读为一个错误。以下文件对此进行了说明: 表4:Flatfile TraceListener属性 注意: 如果您为 FlatfileTraceListener是只读的, 跟踪侦听器不写入 将数据添加到文件中,没有异常 发生。确保文件 属性设置为读/写
因为它不认为它是一个错误,它不会被特殊类别的“日志错误和警告”所捕获,因此不会写入事件日志(在您的情况下)。 虽然文档没有明确说明权限问题会发生相同的情况,但我已经厌倦了使用配置文件(分别为只读和无权限),并且显示了相同的行为
不幸的是,您似乎没有什么选择,只能确保文件是可写的,并且执行应用程序的用户具有正确的写入权限