简体   繁体   English

Azure Function 记录调用的每个方法并记录到 Azure Log Analytics 工作区

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

Currently, I have a project which is using Azure Function with .net core 3.1 and I would like to know how to trace every method called for example:目前,我有一个使用 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;
    }

And it will record to Azure Log Analytics workspace without Log.Information("Function:Count Start");并且它会在没有Log.Information("Function:Count Start");情况下记录到 Azure Log Analytics 工作区Log.Information("Function:Count Start"); and Log.Information("selectCount Start");Log.Information("selectCount Start");

Log message Sample as below日志消息示例如下

_________________________________________________
|      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   | 
_________________________________________________

I realize this is not the answer you are looking for, however you cannot achieve such logging without explicitly enabling that in your code.我意识到这不是您正在寻找的答案,但是如果不在代码中明确启用它,您将无法实现此类日志记录。

To what purpose do you not want to have those lines in your code?您不想在代码中包含这些行的目的是什么?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM