Search code examples
asp.net-mvcloggingc#-3.0ninjectdomainservices

Error Logging in Asp.net mvc app inside web application or domain layer?


I just want to know what would be best practice/ widely used, I currently do my logging in the domain service layer, however anything that happens inside my web application layer is not logged.

I would like one centralized and simple location to do all my create/delete/update loggging...

I have heard of Elmah, not sure how useful it is for domain service layer logging only...

I currently do not use any framework for logging at all, I just string builder my log message or get the exception and flush it into the database... Is this the best way to go about it?

If it matters... I need to use Ninject to inject in my ILoggingService

NOTE: I am not talking about Logging User Activity... that will definetly reside only inside my domain service layer...


Solution

  • Haroon,

    Leverage Ninject to create and manage the lifetime of an ILoggingService. The implementation of that service should be built directly on top of a well tested logging library like NLog or log4net.

    Once you have an instance of the service, you can easily inject it into either you MVC controller or your domain layer. All logging should happen against that instance, not a static logging class.

    This will allow you to have the unified logging you are looking for, with a clean separation of concerns.