RE: Log the machine name.

Nicko Cadell <[email protected]> Tue, 3 Feb 2004 13:00:06 -0000
Newsgroups gmane.comp.windows.dotnet.log4net.user
Message-ID <[email protected]>
Jeff,

There isn't a conversion pattern for the machine name but there are a number
of ways of doing this depending on your situation.

If you are using the Remoting, SMTP, SmtpPickupDir or Udp appenders then the
host name is stored in an event property.

If you are using 1.2.0 up to beta7 then the property is called "hostname" if
you are using 1.2.0 beta8 then it is "log4net:HostName".

You can use the %P{log4net:HostName} pattern to read this value.


If you are not using one of these appenders you will need to manually pass
the hostname into log4net. The best place to store it is in the mapped
diagnostic context, MDC. This is a thread local map of values. You can do
this:

MDC.Set("hostname", Environment.MachineName);

This must be done for each thread that calls into log4net.

Use the %X{hostname} pattern to read the value.

Cheers,

Nicko

> -----Original Message-----
> From: Jeff Mabey [mailto:[email protected]] 
> Sent: 30 January 2004 15:30
> To: [email protected]
> Subject: [Log4net-users] Log the machine name.
> 
> 
> I am using log4net and would like to start logging the 
> machine name.  I can't find anything about a conversion 
> pattern that will give me the machine name.  If anyone can 
> help me out with this I would really appreciate it.  Thanks.
> 
>  
> 
> 


-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn