在 .NET 4.0 中使用 Enterprise Library 5.0 日志记录块,这是我正在使用的唯一块,我试图自定义记录的信息以包括调用堆栈、调用程序集名称以及可能的行号。所以我去了我创建的文本格式化程序并添加了一些条目:
Method: {property(MethodName)}{newline}
Call Stack:{property(CallStack)}
所以在匹配的文本格式化程序配置文件条目之后现在看起来像这样:
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="Timestamp: {timestamp} 
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})}{newline}
Method: {property(MethodName)}{newline}
Call Stack:{property(CallStack)}"
name="Text Formatter" />
</formatters>
您可以在其中看到新添加的条目。但是当我运行它时,我的日志条目如下所示:
----------------------------------------
Timestamp: 12/15/2011 9:51:48 PM
Message: Starting up the application
Category: General
Priority: -1
EventId: 0
Severity: Information
Title:
Machine: HCCLI066
App Domain: WindowsFormsApplicationTest1.vshost.exe
ProcessId: 2488
Process Name: C:\Projects\WindowsFormsApplicationTest1\bin\Debug\WindowsFormsApplicationTest1.vshost.exe
Thread Name:
Win32 ThreadId:2636
Extended Properties:
Method: <Error: property MethodName not found>
Call Stack:<Error: property CallStack not found>
我还需要做些什么来查看记录的这些属性吗?如何添加完全自定义的属性,例如“行号”?