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?
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.
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With