csharp TimedLogger ASP.NET CORE

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp TimedLogger ASP.NET CORE相关的知识,希望对你有一定的参考价值。

using System;
using Microsoft.Extensions.Logging;

public class TimedLogger<T>: ILogger<T>
{
    private readonly ILogger _logger;

    public TimedLogger(ILogger logger) => _logger = logger;

    public TimedLogger(ILoggerFactory loggerFactory): this(new Logger<T>(loggerFactory)) { }

    public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) =>
        _logger.Log(logLevel, eventId, state, exception, (s, ex) => $"[{DateTime.UtcNow:HH:mm:ss.fff}]: {formatter(s, ex)}");

    public bool IsEnabled(LogLevel logLevel) => _logger.IsEnabled(logLevel);

    public IDisposable BeginScope<TState>(TState state) => _logger.BeginScope(state);
}

以上是关于csharp TimedLogger ASP.NET CORE的主要内容,如果未能解决你的问题,请参考以下文章

win7+iis7.5+asp.net下 CS0016: 未能写入输出文件“c:WindowsMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NE

理解ASP.NET Core

缩放 ASP.NET 应用程序

表单身份验证、ASP.NET MVC 和 WCF RESTful 服务

ASP.NET Web API 身份验证(Web + 移动)

ASP.NET 核心标识。使用 ApplicationDbContext 和 UserManager。他们是不是共享上下文?