在.NET 4.0中使用Enterprise Library 5.0 Logging Block这是我正在使用的唯一Block我试图自定义要记录的信息,包括Call Stack,调用Assembly name和Line Numbers。所以我去了我创建的文本Formatter并添加了一些条目:
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>
我还需要做些什么来查看这些属性吗?如何添加完全自定义属性,例如“行号”?
答案 0 :(得分:0)
这篇文章比您需要的更多,但它是可靠的:
http://www.codeproject.com/KB/architecture/DistributedLogging.aspx
另一个我发现:
后者适用于4.1,但它可能是一个很好的起点,然后使用Log Block验证5.0中“Whats New”的MSDN文档。