tags:

views:

498

answers:

3

What logging library or approach would you recommend for this case:

  • We want to be able to log both from managed and unmanaged code
  • For the unmanaged code, the implementation should not cross back into managed code, because this could cause our unmanaged threads to get 'caught' during a garbage collection.
  • Performance is a concern

NLog provides a "C" api, but implements it in terms of its managed implementation.

Many of the C logging libraries out there (rlog, glog) are reliant on macros + preprocessing and are not amenable to wrapping with .NET without extensive modification.

I guess I'm looking for something with a native/unmanaged logging core, but a decent .NET managed api as well. Does this exist? If this doesn't exist, what comes the closest?

Followup - Thanks for the responses mentioning log4net. I think Log4Net and NLog both perform ok in a pure managed application, -but-... The app I've been asked to build has unmanaged I/O on a background thread that absolutely cannot afford to be stopped by a garbage collection. If unmanaged c++ code has to call "up" into a managed logger, it stands a chance of being frozen for 200 or even 2000 milliseconds while the garbage collection occurs. That's why I'm looking for a library that is unmanaged at its core. - Dave

+1  A: 

Have you looked at log4net?

I'm not sure if the core is unmanaged or managed, but I've seen it used in several .NET projects.

Dan Rigby
It's written in C#, so managed.
Mitch Wheat
+1  A: 

I've made quite a bit of use of log4net in my C# and VB .Net projects. Haven't used it in C++ since I haven't done C++ since .Net & Java became my primary programming environments a few years ago. But having used log4j and log4net quite a bit I can vouch for both their performance and ease of use.

Links

log4cxx Logging for C++
log4net Logging for .Net

thaBadDawg
Thanks - I'll take a look at log4cxx
Dave Moore
+1  A: 

Pantheios might meet your requirements. It's open-source.

Mitch Wheat