Configure WebORB with Log4Net
Posted by admin on January 17th, 2010This will be a quick one because time is not on my side these days... If you've never worked with Log4Net, I suggest to go and read some documentation on this an try to set it up.
A while ago I was searching how I could merge the logging from WebORB with my Log4Net configuration. As it happens, I had two log files, one from WebORB and one from Log4Net. Having an overview of the logging, was difficult like this. After some initial help from Mark Piller (WebORB), I managed to merge the two loggings. However, in the beginning, some logs were still written to the WebORB log file. After some weeks I got another email from Mark explaining how it could be done so that all logging would go to the Log4Net logging.
So here's how you do it:
In the Weborb.config file, add next lines in the logging tag section:
-
<!--<currentPolicy>Date Based Logging</currentPolicy>-->
-
<currentPolicy>Log4NetPolicy</currentPolicy>
-
-
<loggingPolicy>
-
<policyName>Log4NetPolicy</policyName>
-
<className>Edu3.Weborb.Logging.Log4NetPolicy</className>
-
</loggingPolicy>
The Date Based Logging is the default policy used by WebORB which I commented out. We'll implement a Log4NetPolicy (you can take another name if you wish so).
In the loggingPolicy tag you can map the policy to a className which we'll implement. This class needs to implement the interface Weborb.Util.Logging.ILoggingPolicy, which is an interface in the weborb dll.
Important is to set all the log enables to true. It's Log4Net that will handle levels. If you set, for instance, the WebORB INFO level to enable=false, then our custom Log4Net logger will not receive any INFO loggings from WebORB. Even if you then set INFO level to be logged in Log4Net, the WebORB INFO levels won't be logged.
-
<log enable="yes">WEBORB INFO</log>
-
<log enable="yes">WEBORB DEBUG</log>
-
<log enable="yes">WEBORB ERROR</log>
-
<log enable="yes">WEBORB SERIALIZATION</log>
-
<log enable="yes">WEBORB EXCEPTION</log>
-
<log enable="yes">WEBORB INSTRUMENTATION</log>
-
<log enable="yes">WEBORB SECURITY</log>
-
<log enable="yes">WEBORB MESSAGE SERVER</log>
-
<log enable="yes">WEBORB THREADING</log>
So here's my Edu3.Weborb.Logging.Log4NetPolicy class:
-
using Weborb.Util.Logging;
-
using System.Collections;
-
-
namespace Edu3.Weborb.Logging
-
{
-
class Log4NetPolicy : ILoggingPolicy
-
{
-
private readonly Hashtable _hashtable;
-
private const string PolicyName = "Log4NetPolicy";
-
-
public Log4NetPolicy(Hashtable hashTable)
-
{
-
_hashtable = hashTable;
-
}
-
-
public ILogger getLogger()
-
{
-
}
-
-
public string getPolicyName()
-
{
-
return PolicyName;
-
}
-
-
public Hashtable getPolicyParameters()
-
{
-
return _hashtable;
-
}
-
}
-
}
getLogger() should return the logger object which will be used by WebORB
getPolicyName() should return the name of the policy. Make sure it is the same as you specified in the config file
getPolicyParameters() should return the same hashtable which was passed into your policy constructor
The Log4NetLogger is also a custom written class that looks like this:
-
using System;
-
using log4net;
-
using Weborb.Util.Logging;
-
using log4net.Core;
-
-
namespace Edu3.Weborb.Logging
-
{
-
public class Log4NetLogger : AbstractLogger
-
{
-
private static readonly ILog Log = LogManager.GetLogger("WebORB");
-
-
public override void fireEvent(string category, object eventObject
-
, DateTime timestamp)
-
{
-
Level activityLevel;
-
switch (category)
-
{
-
case LoggingConstants.WEBORB_INFO:
-
activityLevel =
-
Log.Logger.Repository.LevelMap["WEBORB_INFO"];
-
Log.Logger.Log(GetType(), activityLevel
-
, eventObject, null);
-
break;
-
case LoggingConstants.WEBORB_DEBUG:
-
activityLevel =
-
Log.Logger.Repository.LevelMap["WEBORB_DEBUG"];
-
Log.Logger.Log(GetType(), activityLevel
-
, eventObject, null);
-
break;
-
case LoggingConstants.WEBORB_ERROR:
-
activityLevel =
-
Log.Logger.Repository.LevelMap["WEBORB_ERROR"];
-
Log.Logger.Log(GetType(), activityLevel
-
, eventObject, null);
-
break;
-
case LoggingConstants.WEBORB_SERIALIZATION:
-
activityLevel =
-
Log.Logger.Repository.LevelMap["WEBORB_SERIALIZATION"];
-
Log.Logger.Log(GetType(), activityLevel
-
, eventObject, null);
-
break;
-
case LoggingConstants.WEBORB_EXCEPTION:
-
activityLevel =
-
Log.Logger.Repository.LevelMap["WEBORB_EXCEPTION"];
-
Log.Logger.Log(GetType(), activityLevel
-
, eventObject, null);
-
break;
-
case LoggingConstants.WEBORB_INSTRUMENTATION:
-
activityLevel =
-
Log.Logger.Repository.LevelMap["WEBORB_INSTRUMENTATION"];
-
Log.Logger.Log(GetType(), activityLevel
-
, eventObject, null);
-
break;
-
case LoggingConstants.WEBORB_SECURITY:
-
activityLevel =
-
Log.Logger.Repository.LevelMap["WEBORB_SECURITY"];
-
Log.Logger.Log(GetType(), activityLevel
-
, eventObject, null);
-
break;
-
case LoggingConstants.WEBORB_MESSAGE_SERVER:
-
activityLevel =
-
Log.Logger.Repository.LevelMap["WEBORB_MESSAGE_SERVER"];
-
Log.Logger.Log(GetType(), activityLevel
-
, eventObject, null);
-
break;
-
case LoggingConstants.WEBORB_THREADING:
-
activityLevel =
-
Log.Logger.Repository.LevelMap["WEBORB_THREADING"];
-
Log.Logger.Log(GetType(), activityLevel
-
, eventObject, null);
-
break;
-
case LoggingConstants.WEBORB_MESSAGINGEXCEPTION:
-
activityLevel =
-
Log.Logger.Repository.LevelMap["WEBORB_MESSAGINGEXCEPTION"];
-
Log.Logger.Log(GetType(), activityLevel
-
, eventObject, null);
-
break;
-
default:
-
"have been catched previously.");
-
}
-
}
-
}
-
}
As you'll see, I defined some custom log levels in Log4Net. You really don't need this, you could just use the existing Log4Net levels and map custom WebORB levels to one of the existing Log4Net levels.
Here's how my Log4Net configuration section looks like if you want to work with these custom levels.
-
<log4net>
-
<level>
-
<name value="WEBORB_INFO" />
-
<value value="40000" />
-
</level>
-
<level>
-
<name value="WEBORB_DEBUG" />
-
<value value="30000" />
-
</level>
-
<level>
-
<name value="WEBORB_ERROR" />
-
<value value="70000" />
-
</level>
-
<level>
-
<name value="WEBORB_SERIALIZATION" />
-
<value value="40000" />
-
</level>
-
<level>
-
<name value="WEBORB_EXCEPTION" />
-
<value value="70000" />
-
</level>
-
<level>
-
<name value="WEBORB_MESSAGINGEXCEPTION" />
-
<value value="70000" />
-
</level>
-
<level>
-
<name value="WEBORB_INSTRUMENTATION" />
-
<value value="40000" />
-
</level>
-
<level>
-
<name value="WEBORB_SECURITY" />
-
<value value="40000" />
-
</level>
-
<level>
-
<name value="WEBORB_MESSAGE_SERVER" />
-
<value value="40000" />
-
</level>
-
<level>
-
<name value="WEBORB_THREADING" />
-
<value value="40000" />
-
</level>
-
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
-
<file value="Logs/Log4Net/"/>
-
<appendToFile value="true"/>
-
<rollingStyle value="Date"/>
-
<staticLogFileName value="false" />
-
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
-
<datePattern value="yyyy-MM-dd-HH.lo\g" />
-
<maxSizeRollBackups value="10" />
-
<maximumFileSize value="1MB" />
-
<layout type="log4net.Layout.PatternLayout">
-
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline"/>
-
</layout>
-
</appender>
-
<root>
-
<level value="ALL"/>
-
<appender-ref ref="RollingFileAppender"/>
-
</root>
-
</log4net>
In this section you can configure not to log all levels. For more information on this see the Log4Net documentation.
Maybe that some of the Log Levels values (the integers) should be changed to meet your expectations. See Log4Net Levels for more information.
That's about it. If I forgot something, I'll update the post. If you have any question, please feel free to ask.















Recent Comments