Redirecting EDT's own logging messages to log4net is easy.
Firstly, turn off EDT's own log writers as follows:
EnterpriseDT.Util.Debug.Logger.CurrentLevel = EnterpriseDT.Util.Debug.Level.OFF;
then handle the
LogMessageReceived event in the
EnterpriseDT.Util.Debug.Logger class. It's static, so the handler will also need to be static:
EnterpriseDT.Util.Debug.Logger.LogMessageReceived += new EnterpriseDT.Util.Debug.LogMessageHandler(Logger_LogMessageReceived);
.
.
.
static void Logger_LogMessageReceived(object sender, EnterpriseDT.Util.Debug.LogMessageEventArgs e)
{
log4net.Core.Level l4nLevel = GetL4NLevel(e.LogLevel);
if (log.Logger.IsEnabledFor(l4nLevel))
log.Logger.Log(typeof(FTPConnection), l4nLevel, e.FormattedText, e.Exception);
}
and finally add the GetL4NLevel method which convert EDT's logging levels to log4net's logging levels:
private static log4net.Core.Level GetL4NLevel(EnterpriseDT.Util.Debug.Level edtLevel)
{
if (edtLevel == EnterpriseDT.Util.Debug.Level.FATAL)
return log4net.Core.Level.Fatal;
else if (edtLevel == EnterpriseDT.Util.Debug.Level.ERROR)
return log4net.Core.Level.Error;
else if (edtLevel == EnterpriseDT.Util.Debug.Level.WARN)
return log4net.Core.Level.Warn;
else if (edtLevel == EnterpriseDT.Util.Debug.Level.INFO)
return log4net.Core.Level.Info;
else if (edtLevel == EnterpriseDT.Util.Debug.Level.DEBUG)
return log4net.Core.Level.Debug;
else if (edtLevel == EnterpriseDT.Util.Debug.Level.ALL)
return log4net.Core.Level.Verbose;
else
return log4net.Core.Level.Off;
}
- Hans (EnterpriseDT)