dmi*_*eyg 4 logging log4net single-sign-on saml-2.0 kentor-authservices
有没有办法使用log4net作为Kentor Authservices Logger?文档指出"将ILoggerAdapter连接到SPOptions.Logger.如果您正在使用OWIN中间件,这将自动为您完成,您可以在OWIN/Katana日志记录中看到输出."但我真的不明白它的意思是.
您可以在log4net记录器和Kentor.AuthServices记录器之间编写一个适配器,如下所示:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
然后将其实例分配给您的AuthServices Options.SPOptions.Logger.例如,在SampleMVCApplication Global.asax.cs中,添加一行Application_Start:
Kentor.AuthServices.Mvc.AuthServicesController.Options.SPOptions.Logger =
new log4netLoggerAdapter(log4net.LogManager.GetLogger("AuthServices"));
Run Code Online (Sandbox Code Playgroud)
最后一部分当然会有所不同,具体取决于您使用的模块以及如何加载配置,但关键是分配ILoggerAdapter给您的SPOptions.Logger