I'm using ServiceStack for some time and had a setup with some basic logging using ServiceStack.Logging package. It works well to log the exceptions that go up the call stack.
In some cases I may need to log an event further on the stack. My structure is something like this:
I have also a ServiceBase that setup the logging interface as following:
public abstract class MyServiceBase : Service
{
public ILog log = LogManager.GetLogger(typeof(MyServiceBase));
}
What is the best approach to log information inside this BLL layer? Currently, I only see the option of passing the ILog
instance to the BLL class and use it down there.
Is there any other option?
Thanks!
You should never need to pass along the ILog instance. The LogFactory takes care of this. When your web application is starting up you need to set the LogManager via the following command:
ServiceStack.Logging.LogManager.LogFactory = new Log4NetFactory();
Once its is setup LogManager will always resolve to the correct logger.
public ILog log = LogManager.GetLogger(typeof(MyServiceBase));
All you ever have to do is add the logging property to each class you want logging and ensure the code always runs after you set the LogFactory.
For other project/solutions: You can add the ServiceStack.Logging project to anything that needs logging. It is a lightweight solution and decouples you from Log4Net. Making changing logging implementations trivial. If you use ServiceStack's logging then all your logging and the internal ServiceStack logging will log together.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments