Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何自定义loggingConfiguration的格式化程序?_Asp.net_Logging_Exception Handling_Enterprise Library - Fatal编程技术网

Asp.net 如何自定义loggingConfiguration的格式化程序?

Asp.net 如何自定义loggingConfiguration的格式化程序?,asp.net,logging,exception-handling,enterprise-library,Asp.net,Logging,Exception Handling,Enterprise Library,我不熟悉EnterpriseLibrary.Logging。在web.config的loggingConfiguration下,我们有以下格式化程序: <formatters> <add name="Default Formatter" template="&#xA;Timestamp: {timestamp(local)}&#xA;&#xA;Message: {message}&#xA;&#xA;Category: {categ

我不熟悉EnterpriseLibrary.Logging。在web.config的loggingConfiguration下,我们有以下格式化程序:

<formatters>
    <add name="Default Formatter" template="&#xA;Timestamp: {timestamp(local)}&#xA;&#xA;Message: {message}&#xA;&#xA;Category: {category}&#xA;&#xA;Priority: {priority}&#xA;&#xA;EventId: {eventid}&#xA;&#xA;Severity: {severity}&#xA;&#xA;Title:{title}&#xA;&#xA;Machine: {machine}&#xA;&#xA;Application Domain: {appDomain}&#xA;&#xA;Process Id: {processId}&#xA;&#xA;Process Name: {processName}&#xA;&#xA;Win32 Thread Id: {win32ThreadId}&#xA;&#xA;Thread Name: {threadName}&#xA;&#xA;User Name: {userName}&#xA;&#xA; extended Properties: {dictionary({key} - {value}&#xA;)}" 
             type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <add name="DBA Formatter" template="&#xA;Timestamp: {timestamp(local)}&#xA;&#xA;Message: {message}&#xA;&#xA;Category: {category}&#xA;&#xA;Priority: {priority}&#xA;&#xA;EventId: {eventid}&#xA;&#xA;Severity: {severity}&#xA;&#xA;Title:{title}&#xA;&#xA;Machine: {machine}&#xA;&#xA;Extended Properties: {dictionary({key} - {value}&#xA;)}" 
             type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</formatters>


在代码隐藏中,我们只将消息设置为LogEntry。我想知道其他参数是如何设置的,例如时间戳、类别、优先级等。我已经添加了用户名,但不起作用。有人能帮我解释一下吗?

这是微软关于这些参数的文章:。它讨论了可以在格式化程序中插入的各种标记

“用户名”不是预定义的令牌之一。但您可以(可能)使用LogEntry的ExtendedProperties属性来解决这个问题:

 LogEntry le = new LogEntry();
 le.ExtendedProperties.Add("username", "jsmith");