In java world you have log4j and a a pretty decent logging framework, is there anything like that for C#/.NET?
-
3Not to be the dupe police, but this is a dupe of a dupe. Hell, if you just put [C#] and [Logging] tags in the search your first answer is almost this exact question. – mmcdole Feb 08 '09 at 05:02
-
1duplicate question. There are many same questions on stackoverflow. – Shekhar Oct 14 '10 at 06:11
-
ATTENTION there is a comprehensive list of logging frameworks here: https://github.com/quozd/awesome-dotnet/blob/master/README.md#logging – James Ko Feb 24 '18 at 04:47
16 Answers
-
1
-
1I heard that Log4net has a dependency on System.Web which makes it a unreliable choice for projects using the `.net client framework`, is this true? – Ingó Vals Jul 31 '12 at 13:55
-
@IngóVals It has support for .net framework client profile 3.5 and 4.0. http://logging.apache.org/log4net/release/manual/introduction.html – atoMerz Apr 03 '14 at 16:07
-
http://www.nlog-project.org/ - NLog
It's a very flexible and configurable logging tool that's very light-weight. You can set it up to log to many different locations (Console, SQL, File... etc). Very easy to use.
It's even used by Rob Connery in his Storefront MVC project... http://blog.wekeroad.com/mvc-storefront/

- 12,834
- 2
- 50
- 72
If you are looking for a simple non-bloat solution (the download is only about 100K and the actual dll about 40K), I've successfully used BitFactory on a number of projects.
It's small, configurable, reliable and free!

- 46,440
- 34
- 114
- 174
-
3The author of BitFactory is now asking for a small license fee in order to download the most current version of the library. However, the fee is really exceptionally small - $5 for a single developer, $29 for 10 devs, and $49 for a site license. Older versions also appear to be available for free download. – quentin-starin May 06 '10 at 21:29
Try the Enterprise Library Logging Application Block
Even though I have used a few others mentioned here too - it is worth looking into.

- 3,477
- 3
- 17
- 8
-
Well, looks like that library has [fallen out of support](https://learn.microsoft.com/en-us/previous-versions/msp-n-p/ff648951(v=pandp.10)), now. – jpaugh May 29 '19 at 23:06
There's also nLog, which is rather similar, but a bit more lightweight with less configuration.

- 101,701
- 37
- 181
- 258
The comments here seem to agree with Developer Dude and nzpcmad, as do I. Use Bit Factory, also called The Object Guy's Logging Framework.
As I've said in a few other places, I agree with others here about The Object Guy's Logging Framework. Like Developer Dude says, it isn't bloated -- like some other frameworks out there. It works in all our production applications--and has been doing so for several years now.

- 213
- 4
- 3
We've always used the MS P&P Enterprise Library Logging Application Block. It's not particulary cool or elegant, but it is pretty flexible and well designed. Main reason I think we use it is that we use a lot of the other components from the EL, and they of course all have dependencies on the logging module. More Info Here.

- 736
- 1
- 5
- 8
Yep. Log4Net.
I've been using it for a while, it has been a life saver!

- 1,320
- 1
- 9
- 16
I'd still say Log4Net is a safer options. Many other open source projects also use it, if you ever include one that does, then you've just reduced a dependency.

- 1,795
- 10
- 14
Is there anything that the Windows Event Log + Log Parser can't do for you?

- 23,435
- 23
- 108
- 157
Actually, if you don't need sophisticated logging options straight out of the box, I would suggest writing a thin interface that defines your logging needs (such as log.debug(), log.error(), etc). This will give you flexibility if you need to change latter, or find problems with your current implementation.
While this doesn't seem like a big gain, it was a big win for us recently when we ported our framework to the Windows Compact Framework, and none of the logging options worked. We were able to slide in a null logger, which saved us on that platform. Of course, evaluate for your specific project and needs.

- 8,362
- 2
- 30
- 41
Look at TraceSources and TraceListeners. It is built into .NET and configured with the config file.

- 7,374
- 8
- 39
- 53
James Newton-King covered log4net vs. Enterprise Library Logging about a year ago, and I think it's still largely up to date. My experience has been with EL only, and it's had ups and downs. It's a lot of configuration in a multi-tier application if you don't take advantage of every bell and whistle, so I'll probably try log4net on my next project.

- 1,702
- 2
- 18
- 34