Correct way to log events in another layer on ServiceStack

rocco

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:

  • ServiceInterface - containing the services
  • ServiceModel - containing the DTOs
  • BLL - the logic layer (I need to log something here)

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!

kampsj

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.

edited at
0

Comments

0 comments
Login to comment

Related

Correct way of implementing a service layer in CodeIgniter applications

The correct way to log, and where to log, in PHP

is there a way to copy a filter from one layer to another layer using python

A correct/common way to log async calls

Is this the correct way to log to a specific target with NLog?

The correct way to ignore log entries with NLog at runtime

What is the best way to correct parse log file?

Is it correct way to log the open connections using CachingClientConnectionFactory

Is there a way to move React events to another file then import it?

Correct way to get output of intermediate layer in Keras model?

Is it the correct way to update QML from thread using multi layer signals?

Is this the correct way to save a pointer to an upper layer object in Python?

What is a correct way to layer styling before begin time of core animation?

Correct way to apply Minibatch Standard Deviation to Keras GAN layer

Servicestack server sent events

Correct way of passing pointer to another thread

Correct way to signal QObject on another thread?

Correct way to pass events back from a view in Android

What is the correct way to deal with the deprecated Fragment events onAttach and onInflate

Correct way of connecting Websocket events to update my React Component

Is this a safe and *relatively okay* way to log certain events asynchronously?

What's the correct way to do a rotating log with python twisted?

System.Diagnostics.Trace - correct way to log exceptions

Is there an accepted way of dealing with events containing ID of another aggregate?

Correct way to call a method of a subclass from another subclass

Correct way to wrap code that blocks before emitting future in another future

Correct way to look up missing values from one dataframe in another

Is this the correct way to allow another view mode to access a view models properties?

The correct way to re-render react component from another component