当实现Serilog调试模式时不起作用[.NET Core 3.1]

问题描述 投票:0回答:1

当首次实现Serilog时,dotnet核心版本为2.2。然后,我们将应用程序版本更新为3.1。后来我看到,当我启动调试模式时,chrome页面无法启动。

我的第一个实现是:

Program.cs:

public static void Main(string[] args)
{       

    var sinkOpts = new SinkOptions { TableName = "_Log", AutoCreateSqlTable = true, BatchPostingLimit = 10 };    

    var columnOptions = new ColumnOptions
    {
        AdditionalColumns = new Collection<SqlColumn>
        {
            new SqlColumn
                {ColumnName = "UserName", PropertyName = "UserName", DataType = SqlDbType.NVarChar, DataLength = 64},
        }
    };

    Log.Logger = new LoggerConfiguration()            
            .WriteTo.MSSqlServer(
                connectionString: appSettings.GetConnectionString("DB"),
                sinkOptions: sinkOpts,
                columnOptions: columnOptions,
                restrictedToMinimumLevel: LogEventLevel.Error
            ).CreateLogger();           
}

然后我创建了一个中间件来从HttpContext捕获一些信息:

public class LogContextMiddleware
{
    private readonly RequestDelegate next;

    public LogContextMiddleware(RequestDelegate next)
    {
        this.next = next;
    }

    public Task Invoke(HttpContext context)
    {
        LogContext.PushProperty("UserName", context.User.Identity.Name);

        return next(context);
    }
}

最终在Startup.cs上使用此中间件

app.UseStaticFiles();
app.UseMiddleware<LogContextMiddleware>(); <--
app.UseHttpsRedirection(); 

就这样...该工作完全在2.2上进行。官方文档说,在Startup.cs上添加“ UseSerilogRequestLogging()”,但无法正常工作...我在哪里丢失?

当首次实现Serilog时,dotnet核心版本为2.2。然后,我们将应用程序版本更新为3.1。后来我看到,当我启动调试模式时,chrome页面没有启动。我的冷杉...

asp.net-core .net-core serilog
1个回答
0
投票

启动应用程序时出现错误消息?连接字符串可以吗?

© www.soinside.com 2019 - 2024. All rights reserved.