logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Romanowski Tomasz <tomasz.romanow...@volvo.com>
Subject setting global, thread and event context properties
Date Wed, 16 Sep 2009 11:31:43 GMT
Hi !


I would like to log values set on different levels of context.
For global and thread context I managed to use Properties of these.
Then I wanted to log a value on event level.
The only way I figured out (I'm log4net beginner) was to use LoggingEvent:

This is how I log information:

        // global context
        const string AgentVersionKey = "AgentVersion";
        const string AgentIDKey = "AgentID";
        const string MACKey = "MAC";
        const string VolumeIDKey = "VolumeID";
        const string BIOSIDKey = "BIOSID";
        // thread context
        const string TTUserIDKey = "TTUserID";
        const string TTClientIDKey = "TTClientID";
        // event context
        const string CallOperKey = "CallOper";
        public static void LogInformation(string callingOperation, string info, params object[]
args)
        {
            string message;

            message = String.Format(info, args);
            LoggingEvent logEvent;
            LoggingEventData logData;

            logData = new LoggingEventData();
            logData.TimeStamp = DateTime.Now;

            logData.Level = Level.Info;
            logData.Properties = new log4net.Util.PropertiesDictionary();
            logData.Properties[CallOperKey] = callingOperation;
            logData.Message = message;

            logEvent = new LoggingEvent(ThisDeclaringType, log.Logger.Repository, logData);

            log.Logger.Log(logEvent);
        }

while layout pattern is like this:
      <conversionPattern value=">>%date [%3thread] %-5level BIOSID:%property{BIOSID}
VolumeID:%property{VolumeID} MAC:%property{MAC} Agent Ver.:%property{AgentVersion} Agent ID:%property{AgentID}
User:%username TTUser:%-15property{TTUserID} TTClient:%-15property{TTClientID}%newline%property{CallOper}
- %message%newline" />

My problem is, that when I'm logging code created event, I have null values for all non-event
set properties, like BIOSID, MAC etc.
CallOper, which is the only property set on event, has right value.
Initially I just used log.Info to log information, and then all then BIOSID, MAC were present
in logs.

What I'm doing wrong ?

BTW.
If I create loggingevent, then am I responsible for setting its call properties ? (I've noticed,
that Timestamp was empty, that's why now I assign it in my code).



Best Regards
Tomek
--
  Tomek Romanowski





Mime
View raw message