企业库 3.1 - 如何向侦听器添加新的配置属性添加标签?
我想根据警告、错误等严重性过滤跟踪侦听器。
这意味着如果在配置文件中写入以下侦听器并添加新属性“severityFilter”,则此侦听器将仅捕获警告和以上日志。
那么如何通过代码创建这个名为“severityFilter”的新属性呢?
<add databaseInstanceName="DB1" writeLogStoredProcName="WriteLog"
addCategoryStoredProcName="AddCategory" formatter="Text Formatter"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Database Trace Listener" severityFilter="Warning" />
谢谢 米特什·帕特尔
I want to filter Trace Listener based on Severity like Warning,Error etc.
Means if write below listener in the configuration file and add new property "severityFilter" then this listener will catch only Warning and above logs.
So how to create this new property called "severityFilter" bye code ?
<add databaseInstanceName="DB1" writeLogStoredProcName="WriteLog"
addCategoryStoredProcName="AddCategory" formatter="Text Formatter"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Database Trace Listener" severityFilter="Warning" />
Thanks
Mitesh Patel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法向现有侦听器添加任意配置属性。侦听器属性在配置数据类中定义(在您的示例中
FormattedDatabaseTraceListenerData
)。如果您想添加新的配置属性,则必须创建一个自定义侦听器。类别有一个
SourceLevel
过滤器,可让您按严重性进行全局过滤。但是,如果您想在 TraceListener 的基础上执行此操作,那么您应该升级到企业库的较新版本 - 支持该功能。另一种选择是自定义过滤器,但它作用于 LogEntry,因此也不依赖于 TraceListener。
You can't add arbitrary configuration properties to the existing listeners. The listener properties are defined in a configuration data class (in your example
FormattedDatabaseTraceListenerData
). If you wanted to add new configuration properties you would have to create a custom listener.Categories have a
SourceLevel
filter which let's you globally filter by severity. But if you want to do it on a TraceListener basis then you should upgrade to a newer version of Enterprise Library -- that feature is supported.Another option is a custom filter but that acts on a
LogEntry
so is also not TraceListener dependent.