我一直在寻找有关企业库 5.0 日志记录和过滤的文档,但在企业库 CHM 之外找不到与我的场景相关的任何内容。
我记录了几种类型的类别,我想过滤日志以仅选择某些类别。假设我有这些类别 General、Turtle、Rhino.A、Rhino.B、Rhino.C 等很多犀牛。
我只想选择 Rhino 之类的类别。__
我相信我所做的是过滤除 General 或 Turtle 以外的任何东西,但我宁愿尝试挑选任何像 Rhino 一样的东西。__ 甚至一些关于此的文档也会有所帮助。
这是我目前的配置。
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="false">
<listeners>
<add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" source="Enterprise Library Logging" formatter="Text Formatter" log="" machineName="." traceOutputOptions="None" />
<add name="Rolling Flat File Trace Listener"
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="AppLog.log"
formatter="Short Text Formatter" header="------------------------------------------------------" footer="------------------------------------------------------"
rollInterval="Day" rollSizeKB="1024"
timeStampPattern="yyyy-MM-dd"
rollFileExistsBehavior="Increment"
traceOutputOptions="LogicalOperationStack, DateTime" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" template="Timestamp: {timestamp(local)}{newline}App Domain: {localAppDomain}{newline}Machine: {localMachine}{newline}Title:{title}{newline}Severity: {severity}{tab}Message: {message}{newline}Category: {category}{newline}ProcessId: {localProcessId}{tab}Process Name: {localProcessName}{newline}Thread Name: {threadName}{tab}ThreadId:{win32ThreadId}
" name="Text Formatter" />
</formatters>
<logFilters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.CategoryFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
categoryFilterMode="AllowAllExceptDenied" name="Category Filter">
<categoryFilters>
<add name="General" />
<add name="Turtle" />
</categoryFilters>
</add>
</logFilters>
<categorySources>
<add switchValue="All" name="General" />
<add switchValue="All" name="Turtle" />
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category">
<listeners>
<add name="Rolling Flat File Trace Listener" />
</listeners>
</notProcessed>
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Event Log Listener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
过滤看起来是这样,我正在捕获除 General 和 Turtle 之外的所有内容,这很有效,但似乎有点令人担忧,因为我宁愿只捕获 Rhino 之类的东西。__绝对确保日志中没有其他类别。
<logFilters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.CategoryFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
categoryFilterMode="AllowAllExceptDenied" name="Category Filter">
<categoryFilters>
<add name="General" />
<add name="Turtle" />
</categoryFilters>
</add>
</logFilters>
<categorySources>
<add switchValue="All" name="General" />
<add switchValue="All" name="Turtle" />
</categorySources>