EIF vs log4net

Note: this entry has moved.

I've been doing a comparison of both products recently. Before you read, I must say that I used log4net a lot (I even appear as a contributor :o), so I may be biased. On the other hand, I only evaluated EIF, looked at how it's used in a real world product, and read the documentation provided, as well as built the examples.

Here are my conclusions.

 

Conventions:

·          x: feature is supported equally.

·          -: feature is supported/implemented, but is not as good as the other product

·          +: feature is better supported/implemented than the other product 

 

Feature

EIF

log4net

General

Decoupling of event source and event sink

x

x

Arbitrary target event sinks

x

x

Number of built-in event sinks supported

3

20

Extensible

x

x

Configuration

-

(quite complex)

+

(very simple)

WMI supported built-in

x

 

Arbitrary log data

+

-

(built-in just text)

Multiple logging "domains" (ability to configure the framework by modules, i.e. each logical feature has its own config, repository and sinks)

 

+++

(a BIG plus for highly composed and pluggable apps)

Installation

-

(mostly requires admin permissions)

+

(xcopy)

Support

?

x

(excelent peer support)

Source provided

 

+

Supported Platforms

.NET

.NET, CF, Mono, SSCLI

 

 

 

Runtime

 

 

Performance with logging enabled

x

x

Performance with logging disabled for a certain event

-

++

(orders of magnitude faster)

Reconfiguration

-

(only possible with WMI or Windows Trace)

+

(full configuration monitoring & reloading)

 

 

 

API - Dev friendliness

 

 

Event (source) categorization

-

(uses the event Type. leads to increasingly big hierarchies of event types)

++

(combination of log level + logger name -dotted notation-)

Event source inheritance

 

++

(filters and sinks applied to all descendant sources)

Customization

x

+

(everything)

 

 

 

 

One of the "distinguishing" features of EIF is request tracing, but it is mostly irrelevant as it only works using the remoting CallContext, which reduces its applicability considerably. And remoting is not a long-term platform to rely on either... For request-like tracing on a single thread (important when there're multiple components involved in an operation happening on a single machine/thread) log4net offers similar functionality through its Nested Diagnostics Context.

For business events that rely on arbitrary objects being send, EIF has a clear advantage. I wonder, however, how many business notification scenarios are actually handled through logging... Through customization similar functionality could be implemented in log4net, however.

 

Overall: both seem like good logging packages. EIF may be more manageable as it has strong relationship with WMI. log4net, on the other hand, clearly wins on simplicity and in my opinion satisfies most common logging and tracing needs.

Except for the extra WMI stuff (which can also be implemented as custom extensions to log4net - I've done it) and arbitrary objects publication (also achievable, but requiring more work), I'd choose log4net.

 

Side Note

log4net "event source" (loggers): in log4net, you ask for a logger to the LogManager. Using a simple dotted syntax, you create hierarchycal loggers that inherit sinks, filters and threshold very easily. For example, the following code asks for a logger and logs an informational message:

 

ILog log = LogManager.GetLogger("Finance.Accounting.Customers.Administration");
if (Log.IsInfoEnabled)
{
  log.Info("Adding user " + _userId);
}

 

some other component in the same module may use the following:

 

ILog log = LogManager.GetLogger("Finance.Accounting.Orders");
if (Log.IsInfoEnabled)
{
  log.Info("Adding order " + _orderId);
}

 

All the "Finance" application, or the "Accounting" module can be configured in a single place, and affect both components. A common use is to pass the current component type to the GetLogger() method, therefore making the logger match class full names, which is also an easy way to configure groups of components or modules in an application. For example:

 

<!-- Enables all logging events in finance application (both components above) -->
<logger name="Finance ">
  <level value="ALL" />
</logger>
 
<!-- Enables INFO logging events in accounting module (both components above) -->
<logger name="Finance.Accounting">
  <level value="INFO" />
</logger>
 
<!-- Enables INFO logging events in Orders module (only for the last code above) -->
<logger name="Finance.Accounting.Orders">
  <level value="INFO" />
</logger>

 

Custom logger levels can be used directly, without previous definition, for example "BusinessEvent" or "CriticalOperation". This functionality, combined with hierarchycal loggers is very flexible and completely removes the need in EIF for defining custom types for every event. In addition, arbitrary key-value (only strings) can be logged by using a so-called Mapped Diagnostics Context. Functionality similar to request tracing in EIF is available through Nested Diagnostic Context, that is threads-specific.

 

 

I'd love to hear arguments in favor of EIF. I may be missing some other features it has to offer, or I may have misunderstood some of its functionality, as (like I said) I haven’t used it before.

Have you used both products? What do you think about the points made above?

21 Comments

  • I agree with your point, although I have to admit I'm a little biased as well since I haven't done much with EIF other then mess around with some of the samples. We're using log4net for most of our apps/frameworks and have had a lot of success.

  • Agreed - Log4Net is certainly the way to go.

  • Did you try the Logging Application Block? I think it does provide additional functionality on top EIF.

  • I checked the block, Andres, and it does add logging levels and 2 more event sinks. Except for those two small improvements, however, all the other features shown in the comparison remain as-is.

  • Do you think that EIF, Log4Net or Logging Application Block is overkill for some simple tracing in ASP.NET?



    Basically, I use System.Web.TraceContext for tracing right now and it goes to Trace.axd which is hard to use in the production. I'd rather use System.Diagnostics space for tracing - I'm currentlt investigating whether that is possible at all - and write out to a text file or even user an XmlWriter for later parsing.



    Any suggestions?

    Thanks

  • Well Jiho, the issue is that System.Diagnostics.Trace statements are never sent to the output if you've compiled the app in Release mode. That means you can't turn on tracing on a production app without stopping it and deploying a Debug version.

    As for System.Web.TraceContext, I've heard it's being unified with System.Diagnostics.

    I believe log4net is never overkill, as it adds minimal overhead and is really easy to get up an running. I'm not so sure with EIF/Logging Block...

  • No, unless you remove the default TRACE define in your VS.NET, TRACE is enabled for release builds, I believe.



    I just can't seem to get System.Diagnostics.Trace working under asp.net though. Any idea?



    In any case, I'll definitely check out log4net.



    Thanks

  • BTW, I see your name listed as one of the contributors. Good stuff :).

    I wanted to ask you, is it production ready? (I see that the project itself is in &quot;incubation&quot; status, whatever that means)

  • Oh, you're right!

    I believe there's an article on CodeProject explaining an issue with Trace... can't remember if it was specifically for ASP.NET or not...

  • Hehe, you're right, I'm a contributor :D

    It's definitely production ready. I've used it in a big production project already, with excelent results (including cluster-wide logging, debugging and &quot;request tracing&quot;!). I believe it's in &quot;incubation&quot; because it was very recently moved to the Apache foundation.

  • Couldn't agree more. I tried EIF personally and evaluated it and the Logging application block at work and I found them to be a bit heavy. Way too many dependent configuration entries for my preference.

  • Hola Daniel! I haven't used log4net yet but have been meaning to check it out -- thanks for the high-level scorecard! I have, however, used EIF quite extensively and am both satisfied and disappointed:



    PROS

    ====

    - Request tracing

    - Fine-grained XML configuration

    - Customized event schemas

    - WMI and windows trace providers

    - Good extensibility hooks



    CONS

    ====

    - &quot;Black box&quot; assemblies with no transparency into the implementation (there's always Reflector!) -- big minus

    - Initial installation of above. So much for xcopy deployment -- another big minus

    - Request tracing perf hit. EIF recursively reflects your assemblies to bootstrap this functionality the first time you make a request tracing call. This killed my EIF-instrumented NT service and the SCM shot my service in the head in my OnStart() routine because EIF was blocking. BIG, BIG MINUS

    - Config file is (overly?) complex (although once you get your head around it it's not so bad...)

    - Big work if you want to come up with your own custom EIF schema -- check out Shadowfax to see how much work you have cut out for you!



    What I'd really like is an aspect-oriented instrumentation framework. Why do I have to manually put in method enter/exit trace calls? This is one of the few compelling &quot;cross-cutting&quot;, aspect-oriented concerns that really makes a lot of sense...

  • Does anyone suggest isolating themselves from the logging system they use by using IoC (inversion of control) or dependency injection ? Couldn't this also allow you to ship components whose logging could be changed by a customer ?

  • You're certainly right Ninse. But there are a couple things that should be in-place in order for that to work: first, an IoC infrastructure, which is not all that common in .NET apps, and second, an abstraction of the logging features as a lowest common denominator of both EIF and log4net.

    Both are certainly achievable, IMO... it would be interesting to see how this could be handled by PicoContainer for example... still haven't find the time to take a closer look at it :(

  • We are currently debating exactly this topic. Should we pick a standard logging solution and use it directly, or abstract ourselves from it in some fashion (IoC, Events, Interfaces, etc.)? IMO the lowest common denominator bewteen log4net and EIF/Logging Block would be pretty low! I am not sure that would be very useful. To me, it seems that the only time EIF wins is if you need integration with WMI and custom WMI schema and this probably precludes a lowest common denominator solution. It would be nice to see log4net extended to allow for &quot;arbitrary object publication&quot; as you put it. Then you could simple publish EIF event classes right through log4net.

  • here iam

    iam sure that every one here must be very well used with log4net,

    i have a query,

    basically iam new to log4net,

    i've tried logging files using FileAppender in a web based ASP.NET application,what happens actually, there are no errors occuring but the log file is not written in the Virtual directory, but the scope of application is to write the log files in the virtual directory only.

    i've given the basic part of web.config file below



    &lt;appender name=&quot;LogFileAppender&quot; type=&quot;log4net.Appender.FileAppender,log4net&quot;&gt;

    &lt;param name=&quot;File&quot; value=&quot;logfile.txt&quot; /&gt;

    &lt;param name=&quot;AppendToFile&quot; value=&quot;true&quot; /&gt;

    &lt;layout type=&quot;log4net.Layout.PatternLayout,log4net&quot;&gt;

    &lt;param name=&quot;ConversionPattern&quot; value=&quot;%d [%t] %-5p %c [%x] - %m%n&quot; /&gt;

    &lt;/layout&gt;

    &lt;/appender&gt;





    according to the config the logfile.txt should be written in the virtual directory of the application but it does not do so....



    can any one suggest me with a solution or pinpoint the error which i have done..



    with regards,

    kathik,

    karthik@i7asia.co.in,

    i7software asia pvt ltd.,

  • Most probably, you're having a security problem. Try creating the file by hand, and set appropriate permissions on it (write for ASPNET account). The quick and dirty way is to set Everyone - Full Control on the development machine. This is because the authentication scheme as well the operating system you're using may require different permissions on the file (i.e. in Windows 2003 you have to authorize the NETWORK SERVICE account instead of ASPNET).



    HTH

  • Thanks Daniel,



    i found it working, i.e., the file is written in System32 folder but what we really need here is the file should be written in the application directory itself., i.e in the folder where the project file is residing, that too using the release version of log4net..





    could u help me....

  • Karthik, try putting this in your Application_Start:



    Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;



    I cannot promise this will work as I have never used log4net and am just reading through this discussion to get a feel for it and decide whether or not I want to use it. But I see that no one has answered your message and it has been a while, and I am guessing it is getting logged to Environment.CurrentDirectory (since you said it was logging to System32), so if you want it to instead log to your virtual directory, doing the above should accomplish that.



    Brad

  • Microsoft came to us over a year ago to discuss their current block offerings and potential future ones.



    (We're an investment bank doing lots of .net high transaction, performance intensive work, so they were/are trying to target their neediest customers)



    Anyway, at the time, the logging block didn't exist, and they asked the room about potentially creating / offering one. The room (every non MS person) unanimously said log4net. MS seemed to agree at the time that log4net was a complete package that worked very well (and remarkably similar to the more recently developed exception block, interesting...) so their priorities would be focused towards other blocks the development community would value more.



    A few months later the logging block came out. Doesn’t work as well or as easily as log4net. Why did they bother? Now we’ll have to wait for version 3 of the block for it to match what log4net did in 2002..

  • how do i write the logs in one central server

    we use winforms and the client does not have accsess to SQL

    Do log4net use webservice or remoting etc?

    thx

    dany smirnoff

Comments have been disabled for this content.