qmo
qmo

Reputation: 3198

Logging Exceptions with OWIN Middleware

We have a self-hosted WebAPI application using OAuthBearerAuthenticationHandler and I see it logs exception using (ILogger)_logger when an exception is thrown. Since we are using our own logging framework, how can I supply my own ILogger to OAuthBearerAuthenticationHandler?

Upvotes: 4

Views: 1840

Answers (1)

qmo
qmo

Reputation: 3198

The solution for us was to set our won 'LoggerFactory'.

IAppBuilder appBuilder ............;
..........
appBuilder.SetLoggerFactory(new OwinLoggerFactory());

And for 'OwinLoggerFactory':

public class OwinLoggerFactory : ILoggerFactory
{
    private readonly ILoggerFactory _baseLoggerFactory;

    public OwinLoggerFactory()
    {
        _baseLoggerFactory=new DiagnosticsLoggerFactory();
    }


    public ILogger Create(string name)
    {
        //create your own OwinLogger class that implements 'ILogger'
        // inside your own OwinLogger class, you may then hook up to any logging Fx you like.
    }
}

Upvotes: 4

Related Questions