Thursday, December 30, 2010

Log4Net Tutorial. Just say no to blindly copying configs…

CodeProject - Log4net Tutorial - Learn how to use log4net without fear. Stop copying config files and figure out how to make log4net do exactly what you want.

Introduction

One of the greatest logging tools out there for .NET is Log4Net. This software is the gold standard for how logging should be done. It is simple, powerful, and extensible. The best part is that it is part of the FOSS community. What could be better? The one thing I see that is, in my opinion, a bit lacking is a straight-forward tutorial on how to use Log4Net. The documentation covers, in depth, how to use the software but it is a bit obscure. Basically, if you already know what Log4Net can do and you just want to know the syntax, the documentation is for you. The tutorials out there usually cover one piece or one type of system. I am hoping to at least add to the tutorials that are out there and maybe I might just provide you with a complete tutorial including questions to some of the problems I encountered. The below examples and information is based upon the documentation provided by the log4net group.

The Basics

There are a three parts to Log4Net. There is the configuration, the setup, and the call. The configuration is typically done in the app.config or web.config file. We will go over this in depth below and we will offer some alternatives in a future article should you desire more flexibility. The setup is basically a couple of lines of housekeeping that need to be called at the beginning of any class in order to set up and instantiate a connection to the logger. Finally, the simplest part is the call itself. This, if you do it right, is very simple to do and the easiest to understand.

pagesnap…”

Been a long time since I’ve blogged about Log4Net and this project’s subtitle really caught my eye…

I really liked how this article went into depth on the different filters and appenders. If you are using, or thinking about using Log4Net then this is a must read article.

 

Related Past Post XRef:
Linq DataContext.Log to Log4Net - Using Log4Net to log the SQL generated by Linq to SQL

2 comments:

Anonymous said...

Looking back at the end of the year, I find your blog is outstanding, thank you for your work.

Happy New Year!

Timothy Corey said...

I just stumbled across this blog post today. I was the guy who wrote that CodeProject article. I'm glad you found it useful and I appreciate you sharing it with others.