Basic Setup in .NET
2009-01-08 00:57:15 GMT
I'm trying to get log4net setup with my .NET project, using VS 2008.
I'm completely new to the log4net API, and to logging systems in
general, and so I want a very basic logger for my first time out of the
My solution consists of several projects (one executable and several DLLs), and many classes exist inside each project. Since I want to use log4net in a very simple way (even if doing so compromises standard or best practices), I want to use it to log all "errors" (caught exceptions) to the same log file (errors.log). So, for instance, if the CWidget class belongs to the Something project, and it throws an error, I want that error logged in the same file as, say, an exception thrown by the CBlort class, which belongs to the SomethingElse project. So basically:
// Some code.
// Log the exc.Message string to the error.log file.
.. will be my mechanism for logging, at least for now until I understand log4net a little better. The following questions all aim to help me achieve just this. And please, if the nature of my questions indicate that I don't grasp something, feel free to tear into me and explain to me how I've strayed from the path!
(1) I believe what I am looking for is a FileAppender. I would like to configure my project to use a single FileAppender that I will write (borrowing heavily from online examples) in XML. Where does this XML-based config file have to be stored (path) inside the solution?
(2) So the logger now appends log info to a file via FileAppender...where do I store (path) my error.log file so that the logger will work?
(3) Since all objects across all projects will only use this single FileAppender for logging to my error.log file, *instead* of declaring a new logger object inside of each class, I'd like to use a generic logger that all objects have access to. So in one project I am planning to have a class called CLogger that basically wraps a log4net logger, and then any class can reference/use it to log to error.log.... but now that I think about it...
(4) ... Is it possible to create a single logger using XML or some other config method, and then only declare a new instance of it inside every logging class? Or is that what the standard already is with the "ILog log = new ILog.LogManager(...)" statements I see in most examples? I'm so confused!
Thanks for any clarification here, any and all advice will be tremendously helpful to me.