Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 872
qmo Avatar asked Oct 28 '25 08:10

qmo


1 Answers

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.
    }
}
like image 164
qmo Avatar answered Oct 29 '25 21:10

qmo