简体   繁体   English

使用 Serilog 进行 Azure 日志分析停止日志记录(MVC 核心)

[英]Azure log analytics with Serilog stopped logging (MVC Core)

I have a pretty simple MVC Core 2.2 application that is utilizing Serilog and serilog-sinks-azure-analytics ( https://github.com/saleem-mirza/serilog-sinks-azure-analytics ) to pipe application logs to an Azure log analytics workspace.我有一个非常简单的 MVC Core 2.2 应用程序,它利用 Serilog 和 serilog-sinks-azure-analytics( https://github.com/saleem-mirza/serilog-sinks-azure-analytics )将应用程序日志通过管道传输到 Azure 日志分析工作区。 The implementation looks like this in Program.cs 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();
        }

It collected logs for all of day then apparently stopped as when i query the last few hours via the log analytics workspace it returns nothing.它收集了一整天的日志,然后显然停止了,因为当我通过日志分析工作区查询过去几个小时时它什么都不返回。 If I run a query for the last 7 days I get a count of 350 records which is interesting.如果我在过去 7 天内运行查询,我会得到 350 条记录,这很有趣。

The documentation for the sink project states that the logBufferSize is 25,000 entries by default so it doesn't seem like I am hitting that. sink 项目的文档指出,默认情况下 logBu​​fferSize 为 25,000 个条目,因此我似乎没有达到这一点。

I would appreciate any suggestions on how to diagnose where my logs are or why it might be failing.我将不胜感激有关如何诊断我的日志在哪里或它可能失败的原因的任何建议。

Thanks in advance.提前致谢。

There is a limit of about 500 custom fields per log analytics workspace .每个日志分析工作区有大约 500 个自定义字段的限制

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

You could use Serilog.Sinks.AzureAnalytics .您可以使用Serilog.Sinks.AzureAnalytics This sink accepts an option parameter flattenObject dictating if object properties should be flatten out when exporting to Azure.此接收器接受一个选项参数flattenObject该参数指示在导出到 Azure 时是否应展平对象属性。 Setting it to false will retain complex object structure in LogProperties property.将其设置为 false 将在LogProperties属性中保留复杂的对象结构。

For more details, you could refer to this issue .更详细的可以参考这个issue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Serilog 记录到 Azure Log Analytics 自定义字段 - Logging to Azure Log Analytics custom fields using Serilog 在 .NET Core MVC 中使用 Serilog 使用 Azure 表存储进行日志记录 - Using Serilog for Logging with Azure Table Storage in .NET Core MVC 将项目移动到 .Net Core 5 后,Serilog 日志记录到 Azure eventthub 停止工作 - Serilog logging to Azure eventhub stopped working after moving project to .Net Core 5 Serilog + Azure - Log Analytics 工作区中没有出现自定义日志 - Serilog + Azure - No custom logs appearing in Log Analytics workspace 通过Serilog在Azure上记录ASP.NET Core - Logging ASP.NET Core on Azure via Serilog 使用 Azure Log Analytics 在 Azure Function v3 中进行结构化日志记录 - Structured logging in an Azure Function v3 with Azure Log Analytics 使用Serilog .NET Core进行日志记录不会输出 - Logging with Serilog .NET Core not outputting 使用Serilog的MVC日志记录未序列化对象 - MVC logging with Serilog not serializing objects 将Serilog与Azure Log流一起使用 - Use Serilog with Azure Log Stream 使用 serilog 关闭 asp.net 核心 2.2 中的 mvc 请求日志记录 - Turn off mvc request logging in asp.net core 2.2 with serilog
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM