Search code examples
c#loggingerror-logging

Separating Logging Code from C# Objects


Currently I have a custom built static logging class in C# that can be called with the following code:

EventLogger.Log(EventLogger.EventType.Application, string.Format("AddData request from {0}", ipAddress));

When this is called it simply writes to a defined log file specified in a configuration file.

However, being that I have to log many, many events, my code is starting to become hard to read because all of the logging messages.

Is there an established way to more or less separate logging code from objects and methods in a C# class so code doesn't become unruly?

Thank you all in advance for your help as this is something I have been struggling with lately.


Solution

  • I like the AOP Features, that PostSharp offers. In my opinion Loggin is an aspect of any kind of software. Logging isn't the main value an application should provide.

    So in my case, PostSharp always was fine. Spring.NET has also an AOP module which could be used to achieve this.