簡體   English   中英

使用 Serilog 進行 Azure 日志分析停止日志記錄(MVC 核心)

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

我有一個非常簡單的 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 個條目,因此我似乎沒有達到這一點。

我將不勝感激有關如何診斷我的日志在哪里或它可能失敗的原因的任何建議。

提前致謝。

每個日志分析工作區有大約 500 個自定義字段的限制

轉到 Azure 門戶 > Log Analytics workspace > advanced settings > Data -> Custom fields for the current field count並檢查計數。

您可以使用Serilog.Sinks.AzureAnalytics 此接收器接受一個選項參數flattenObject該參數指示在導出到 Azure 時是否應展平對象屬性。 將其設置為 false 將在LogProperties屬性中保留復雜的對象結構。

更詳細的可以參考這個issue

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM