log4net configuration starts adding stuff from other classes

E

Enter The

I'm trying to learn the use log4net.

When I set the configuration in the attached class, I get a load of
INFO messages from a component that I have installed (Nesper).

Why does my code affect Nesper's logging? i only want the logging to
log stuff that I tell it to. but for some reason the configuration
affects the logging of an external component over which I have no
control.

i.e. I only want it to log stuff when I call MyLogger.Debug("Helllo
World");

And to ignore all the stuff that's already in place.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using log4net;
using log4net.Config;

namespace WindowsFormsApplication1
{
class MyLogger
{
//http://www.csharptocsharp.com/log4net-configuration-for-
rockin-loggin-part-2

private static log4net.ILog llog;

static MyLogger()
{
Console.WriteLine("Making static logger class");

/*
System.IO.FileInfo fi = new System.IO.FileInfo("c:\\Users\
\hal\\Documents\\Visual Studio 2008\\Projects\
\WindowsFormsApplication1\\WindowsFormsApplication1\
\WindowsFormsApplication1.exe.cfg");
fi.Open(System.IO.FileMode.Open);
DOMConfigurator.Configure(
fi
);
*/
log4net.Appender.RollingFileAppender rfa = new
log4net.Appender.RollingFileAppender();
rfa.AppendToFile = true;
rfa.RollingStyle =
log4net.Appender.RollingFileAppender.RollingMode.Size;
rfa.MaxSizeRollBackups = 10;
rfa.MaximumFileSize = "1MB";
rfa.StaticLogFileName = true;
rfa.Layout = new log4net.Layout.PatternLayout(@"{%level}
%date{MM/dd HH:mm:ss} - %message%newline");
rfa.File="c:\\log.log";
rfa.ActivateOptions();
;


log4net.Config.BasicConfigurator.Configure(rfa);

llog.Logger.Repository.

llog = log4net.LogManager.GetLogger(typeof(Form1));
//log4net.Filter.


llog.Debug("Logger hello world");

}

public static void Debug(string s){
llog.Debug(s);
}
}
}
 
J

Jesse Houwing

* Enter The wrote, On 29-1-2010 19:16:
I'm trying to learn the use log4net.

When I set the configuration in the attached class, I get a load of
INFO messages from a component that I have installed (Nesper).

Why does my code affect Nesper's logging? i only want the logging to
log stuff that I tell it to. but for some reason the configuration
affects the logging of an external component over which I have no
control.

i.e. I only want it to log stuff when I call MyLogger.Debug("Helllo
World");

And to ignore all the stuff that's already in place.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using log4net;
using log4net.Config;

namespace WindowsFormsApplication1
{
class MyLogger
{
//http://www.csharptocsharp.com/log4net-configuration-for-
rockin-loggin-part-2

private static log4net.ILog llog;

static MyLogger()
{
Console.WriteLine("Making static logger class");

/*
System.IO.FileInfo fi = new System.IO.FileInfo("c:\\Users\
\hal\\Documents\\Visual Studio 2008\\Projects\
\WindowsFormsApplication1\\WindowsFormsApplication1\
\WindowsFormsApplication1.exe.cfg");
fi.Open(System.IO.FileMode.Open);
DOMConfigurator.Configure(
fi
);
*/
log4net.Appender.RollingFileAppender rfa = new
log4net.Appender.RollingFileAppender();
rfa.AppendToFile = true;
rfa.RollingStyle =
log4net.Appender.RollingFileAppender.RollingMode.Size;
rfa.MaxSizeRollBackups = 10;
rfa.MaximumFileSize = "1MB";
rfa.StaticLogFileName = true;
rfa.Layout = new log4net.Layout.PatternLayout(@"{%level}
%date{MM/dd HH:mm:ss} - %message%newline");
rfa.File="c:\\log.log";
rfa.ActivateOptions();
;


log4net.Config.BasicConfigurator.Configure(rfa);

llog.Logger.Repository.

llog = log4net.LogManager.GetLogger(typeof(Form1));
//log4net.Filter.


llog.Debug("Logger hello world");

}

public static void Debug(string s){
llog.Debug(s);
}
}
}

Nesper probably uses Log4Net as well, but as you hadn't configured any
Log configuration, it wasn't writing its messages to anywhere.

Now that you've created a Log configuration in your app.config, it is
picking this up and using it (as instructed, though not by you, by the
developer of Nesper).

I'm not sure if Nesper is using a specific category you could filter.
It's why you should always apply a category to your own messages. That
way you can find them back in case you've got multiple publishers.
 
Top