sách gpt4 ai đã đi

logging - Kentor authservices 和 log4net

In lại 作者:行者123 更新时间:2023-12-02 14:21:14 hai mươi bốn 4
mua khóa gpt4 Nike

有没有办法使用 log4net 作为 Kentor Authservices Logger?文档指出“将 ILoggerAdapter 连接到 SPOptions.Logger。如果您使用 OWIN 中间件,则会自动为您完成此操作,您可以在 OWIN/Katana 日志记录中看到输出。”,但我不太明白是什么意思这意味着。

1 Câu trả lời

您可以在 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);
}
}

然后将其实例分配给您的 AuthServices Options.SPOptions.Logger。例如,在 SampleMVCApplication Global.asax.cs ,在 Application_Start 中添加一行:

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

最后一部分当然会有所不同,具体取决于您使用的模块以及加载配置的方式,但关键是将 ILoggerAdapter 分配给您的 SPOptions.Logger

关于logging - Kentor authservices 和 log4net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45332533/

hai mươi bốn 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com