dmitreyg
dmitreyg

Reputation: 2625

Kentor authservices and log4net

Is there a way to use log4net as Kentor Authservices Logger? Documentation states that "Connect an ILoggerAdapter to your SPOptions.Logger. If you are using the OWIN middleware this is done for you automatically and you can see the output in the OWIN/Katana logging.", but I don't really understand what does it mean.

Upvotes: 4

Views: 807

Answers (1)

Steve P
Steve P

Reputation: 19377

You would write an adapter between the log4net logger and the Kentor.AuthServices logger, something like this:

public class log4netLoggerAdapter : Kentor.AuthServices.ILoggerAdapter
{
    private log4net.ILog _logger;

    public log4netLoggerAdapter(log4net.ILog logger)
    {
        _logger = logger;
    }

    public void WriteError(string message, Exception ex)
    {
        _logger.Error(message, ex);
    }

    public void WriteInformation(string message)
    {
        _logger.Info(message);
    }

    public void WriteVerbose(string message)
    {
        _logger.Debug(message);
    }
}

And then assign an instance of that to your AuthServices Options.SPOptions.Logger. For example, in the SampleMVCApplication Global.asax.cs, adding a line in Application_Start:

Kentor.AuthServices.Mvc.AuthServicesController.Options.SPOptions.Logger =
            new log4netLoggerAdapter(log4net.LogManager.GetLogger("AuthServices"));

This last part would of course be different depending on which module you are using and how you are loading your configuration, but the key is the assignment of an ILoggerAdapter to your SPOptions.Logger

Upvotes: 7

Related Questions