【问题标题】:Azure log analytics with Serilog stopped logging (MVC Core)使用 Serilog 的 Azure 日志分析停止了日志记录(MVC 核心)
【发布时间】:2019-12-16 20:28:44
【问题描述】:

我有一个非常简单的 MVC Core 2.2 应用程序,它利用 Serilog 和 serilog-sinks-azure-analytics (https://github.com/saleem-mirza/serilog-sinks-azure-analytics) 将应用程序日志通过管道传输到 Azure 日志分析工作区。 Program.cs 中的实现如下所示

public static void Main(string[] args)
        {

            var workspaceId = Configuration["AzureLogging:workspaceId"];
            var authenticationId = Configuration["AzureLogging:authenticationId"];
            var logName = Configuration["AzureLogging:logName"];

            //Configure Serilog to add Azure Logging
            Log.Logger = new LoggerConfiguration()
                .WriteTo.AzureAnalytics(
                    workspaceId: workspaceId, 
                    authenticationId: authenticationId,
                    logName: logName
                )
                .MinimumLevel.Information()
                .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                .MinimumLevel.Override("System", LogEventLevel.Warning)
                .CreateLogger();

            CreateWebHostBuilder(args).Build().Run();
        }

它收集了一整天的日志,然后显然停止了,因为当我通过日志分析工作区查询过去几个小时时,它什么也没返回。如果我运行过去 7 天的查询,我会得到 350 条记录,这很有趣。

sink 项目的文档指出 logBu​​fferSize 默认为 25,000 个条目,因此我似乎没有达到这个要求。

对于如何诊断我的日志在哪里或为什么它可能失败的任何建议,我将不胜感激。

提前致谢。

【问题讨论】:

    标签: c# azure asp.net-core-mvc serilog azure-log-analytics


    【解决方案1】:

    每个日志分析工作区限制为大约 500 个自定义字段

    转到 Azure 门户 > Log Analytics workspace > advanced settings > Data -> Custom fields for the current field count 并检查计数。

    您可以使用Serilog.Sinks.AzureAnalytics。此接收器接受一个选项参数flattenObject,指示在导出到 Azure 时是否应展平对象属性。将其设置为 false 将在 LogProperties 属性中保留复杂的对象结构。

    更多详情可以参考这个issue

    【讨论】:

    • 感谢您的回答。目前显示我只使用了 118 个字段。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-05
    • 2021-04-18
    • 2013-12-29
    • 1970-01-01
    • 1970-01-01
    • 2013-02-28
    相关资源
    最近更新 更多