0

目前,我有一个项目正在使用带有 .net core 3.1 的 Azure Function,我想知道如何跟踪每个调用的方法,例如:

    [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;
    }

它将记录到 Azure Log Analytics 工作区,而无需Log.Information("Function:Count Start");Log.Information("selectCount Start");

日志消息示例如下

_________________________________________________
| 时间生成 | 留言 |
|2020/11/17 09:00:00.000 | 功能:计数开始 |
|2020/11/17 09:00:00.002 | 选择计数开始 |
|2020/11/17 09:00:00.003 | 选择计数结束 |
|2020/11/17 09:00:00.001 | 功能:计数结束 |
_________________________________________________
4

1 回答 1

0

我意识到这不是您正在寻找的答案,但是如果没有在代码中明确启用它,您将无法实现此类日志记录。

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

于 2020-11-17T09:21:27.120 回答