簡體   English   中英

Azure Function 記錄調用的每個方法並記錄到 Azure Log Analytics 工作區

[英]Azure Function log every methods called and record into Azure Log Analytics workspace

目前,我有一個使用 Azure Function 和 .net core 3.1 的項目,我想知道如何跟蹤每個調用的方法,例如:

    [FunctionName("Count")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", Route = "Count")] HttpRequest req,
        ILogger log)
    {
        int cnt = selectCount("Select * from A");
    }
    
    public static int selectCount(string str)
    {
        return 2;
    }

並且它會在沒有Log.Information("Function:Count Start");情況下記錄到 Azure Log Analytics 工作區Log.Information("Function:Count Start"); Log.Information("selectCount Start");

日志消息示例如下

_________________________________________________
|      TimeGenerated     |        Message       | 
|2020/11/17 09:00:00.000 | Function:Count Start | 
|2020/11/17 09:00:00.002 | selectCount Start    | 
|2020/11/17 09:00:00.003 | selectCount end      | 
|2020/11/17 09:00:00.001 | Function:Count end   | 
_________________________________________________

我意識到這不是您正在尋找的答案,但是如果不在代碼中明確啟用它,您將無法實現此類日志記錄。

您不想在代碼中包含這些行的目的是什么?

暫無
暫無

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

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