C# 4.0 企业库5.0日志记录块自定义
使用.NET 4.0中的Enterprise Library 5.0日志记录块(这是我正在使用的唯一一个块),我试图自定义记录的信息,以包括调用堆栈、调用程序集名称以及可能的行号。因此,我转到我创建的文本格式化程序,并添加了一些条目:C# 4.0 企业库5.0日志记录块自定义,c#-4.0,enterprise-library-5,C# 4.0,Enterprise Library 5,使用.NET 4.0中的Enterprise Library 5.0日志记录块(这是我正在使用的唯一一个块),我试图自定义记录的信息,以包括调用堆栈、调用程序集名称以及可能的行号。因此,我转到我创建的文本格式化程序,并添加了一些条目: Method: {property(MethodName)}{newline} Call Stack:{property(CallStack)} 因此,匹配的文本格式化程序配置文件条目如下所示: <formatters> &l
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>
您可以在那里看到新添加的条目。但当我运行它时,我的日志条目如下所示:
<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>
我还需要做什么才能看到这些属性被记录下来?如何添加完全自定义的属性,例如行号 这篇文章做的比你需要的要多一些,但它是可靠的: 我发现的另一个例子是:
后者适用于4.1,但这可能是一个很好的开始,然后对照MSDN文档验证5.0中日志块的新功能的地方。这篇文章比您需要的要多一些,但它是可靠的: 我发现的另一个例子是:
后者适用于4.1,但这可能是一个很好的开始,然后对照MSDN文档验证5.0中日志块的新功能。亲爱的Victor,请解释一下如何解决此问题,以使用文本格式化程序显示调用堆栈信息?谢谢Dear Victor,您能解释一下您是如何解决这个问题的,以使用文本格式化程序显示调用堆栈信息的吗?谢谢