你如何通过登录log4net的机器名? [英] How do you log the machine name via log4net?

查看:215
本文介绍了你如何通过登录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.

不过,我不能找到一种方法,通过公开,我现在用的附加器的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?

推荐答案

您可以使用pre填充属性 log4net的:主机名,例如:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆