你如何通过 log4net 记录机器名称? [英] How do you log the machine name via log4net?
问题描述
我使用 Log4Net 和 AdoNetAppender 将来自简单系统托盘应用程序的消息记录到 SQL Server 2005 数据库中.
I am using Log4Net with the AdoNetAppender to log messages from a simple systray application into a SQL Server 2005 database.
我想记录机器名称和日志消息,因为这个应用程序将在多台机器上运行,我需要知道消息是在哪台机器上产生的.
I want to log the machine name along with the log message because this application will be running on multiple machines and I need to know on which one the message originated.
但是,我找不到通过我与 appender 一起使用的 log4net.Layout.PatternLayout 公开这些信息的方法.
But, I cannot find a way to expose this information via the log4net.Layout.PatternLayout that I am using with the appender.
有没有办法以这种方式通过 log4net 记录机器名称?
Is there a way to log the machine name via log4net in this manner?
推荐答案
您可以使用预填充的属性 log4net:HostName
,例如:
You can use the pre-populated property log4net:HostName
, for example:
<conversionPattern value="%property{log4net:HostName}" />
这样您就不需要填充 MDC.
This way you don't need to populate the MDC.
这篇关于你如何通过 log4net 记录机器名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!