You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Aaron Clauson <az...@yahoo.com> on 2004/05/12 14:06:18 UTC

RemotingAppender: HostName and UserName

Hi,

I am using the remoting appender and want to see the
host and user that the log message has originated
from.

The FAQ gives examples of using %P{hostname} and %W
for the username. The hostname property was always
blank and the usename property always returned the
user owning the local logging process not the one the
user of the one that generated the logging message.

After looking in the coded I got the hostname working
correctly by using %P{log4net:HostName}. I am not sure
if this is by design and the FAQ is incorrect or there
is something I have missed?

To fix the username problem I changed the SendBuffer
method of the RemotingAppender class as shown below
and then used %P{log4net:UserName}. Once again not
sure if this is needed or I have missed something?

override protected void SendBuffer(LoggingEvent[]
events)
{
 string hostName =   SystemInfo.HostName;

 // Set the hostname
 foreach(LoggingEvent e in events)
 {
   if (e.Properties[LoggingEvent.HostNameProperty] ==
null)
   {
     e.Properties[LoggingEvent.HostNameProperty] =
hostName;
   }

   string username = e.UserName;

   if (e.Properties[LoggingEvent.UserNameProperty] ==
null)
   {
      e.Properties[LoggingEvent.UserNameProperty] =
username;
   }
 }

  // Send the events
  m_sinkObj.LogEvents(events);
} 

Aaron



	
		
__________________________________
Do you Yahoo!?
Yahoo! Movies - Buy advance tickets for 'Shrek 2'
http://movies.yahoo.com/showtimes/movie?mid=1808405861