【发布时间】:2013-01-28 10:45:45
【问题描述】:
我正在使用 Enterprise Library 5 Logging 块来登录我的 Windows 应用程序,我还为我的日志条目定义了一些扩展属性,当我定义一个数据库跟踪侦听器并使用它来记录我的消息时,我的消息保存在哪里扩展属性?在哪个领域?
【问题讨论】:
标签: database logging listener enterprise-library extended-properties
我正在使用 Enterprise Library 5 Logging 块来登录我的 Windows 应用程序,我还为我的日志条目定义了一些扩展属性,当我定义一个数据库跟踪侦听器并使用它来记录我的消息时,我的消息保存在哪里扩展属性?在哪个领域?
【问题讨论】:
标签: database logging listener enterprise-library extended-properties
扩展属性不会使用开箱即用的数据库跟踪侦听器记录到单独的列或表中。
要记录扩展属性,请配置一个记录扩展属性的格式化程序:
<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}{newline}
Message: {message}{newline}
Category: {category}{newline}
Priority: {priority}{newline}
EventId: {eventid}{newline}
Severity: {severity}{newline}
Title:{title}{newline}
Machine: {localMachine}{newline}
App Domain: {localAppDomain}{newline}
ProcessId: {localProcessId}{newline}
Process Name: {localProcessName}{newline}
Thread Name: {threadName}{newline}
Win32 ThreadId:{win32ThreadId}{newline}
Extended Properties: {dictionary({key} - {value}{newline})}" name="Text Formatter"/>
</formatters>
然后扩展属性数据将被记录到 FormattedMessage 列中。
这样做的缺点是扩展属性隐藏在 FormattedMessage 中。如果您想要扩展属性的更结构化表示,您可以创建自定义数据库跟踪侦听器。
有关将扩展属性记录到单独表的示例,请参阅Extended Properties Trace Listener with Custom Exception Handler。
【讨论】: