Web 项目中使用的 RollingFlatFileTraceListener 导致 NotSupportedException

RollingFlatFileTraceListener used in Web projects cause NotSupportedException

我们在 Web 项目中使用 RollingFlatFileTraceListener:

如果侦听器尝试滚动到新文件,我们会得到一个 NotSupportedException 。

姓名="SeguridadFileListener"

     fileName="C:\Logs\Portal2015\Seguridad.log"
     footer="----------------------"
     formatter="TimeStampAndMessage Formatter"
     header=""
     rollFileExistsBehavior="Overwrite"
     rollInterval="None"
     rollSizeKB="2048"
     timeStampPattern="yyyy-MM-dd HH:mm"
     traceOutputOptions="None"
     filter="All"

我们猜测,fileName 属性中缺少的路径信息会导致路径无效(web url 表示法?),详情如下:

异常信息详情:

Exception Type: System.NotSupportedException
Message: The given path's format is not supported.
Data: System.Collections.ListDictionaryInternal
TargetSite: System.String CanonicalizePath(System.String, Boolean)
HelpLink: NULL
Source: mscorlib

StackTrace 信息详情:

at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)

然后,我也得到了这个错误:

Exception Type: System.NullReferenceException
Message: Referencia a objeto no establecida como instancia de un objeto.
Data: System.Collections.ListDictionaryInternal
TargetSite: Void PerformRoll(System.DateTime)
HelpLink: NULL
Source: Microsoft.Practices.EnterpriseLibrary.Logging
HResult: -2147467261

StackTrace 信息详情:

   en Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener.StreamWriterRollingHelper.PerformRoll(DateTime rollDateTime)
   en Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener.StreamWriterRollingHelper.RollIfNecessary()
   en Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener.TraceData(TraceEventCache eventCache, String source, TraceEventType eventType, Int32 id, Object data)
   en Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.TraceListenerWrapper.TraceData(TraceEventCache eventCache, String source, TraceEventType eventType, Int32 id, Object data)
   en Microsoft.Practices.EnterpriseLibrary.Logging.LogSource.TraceData(TraceEventType eventType, Int32 id, LogEntry logEntry, TraceListenerFilter traceListenerFilter, TraceEventCache traceEventCache)
   en Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl.ProcessLog(LogEntry log, TraceEventCache traceEventCache)

有什么建议吗?

问题是timeStampPattern属性

timeStampPattern="yyyy-MM-dd HH:mm"

字符如 : 对文件路径无效。

timeStampPattern 有效值可以是:

timeStampPattern="yyyyMMdd_HHmm"