【问题标题】:Azure Function log every methods called and record into Azure Log Analytics workspaceAzure Function 记录每个调用的方法并记录到 Azure Log Analytics 工作区
【发布时间】:2021-02-28 07:28:43
【问题描述】:

目前,我有一个项目正在使用带有 .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;
    }

它会在没有Log.Information("Function:Count Start");Log.Information("selectCount Start"); 的情况下记录到 Azure Log Analytics 工作区

日志消息示例如下

_________________________________________________ |时间生成 |留言 | |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 |功能:计数结束 | _________________________________________________

【问题讨论】:

  • 我不完全理解你想要达到的目标。您传递给selectCount 的sql 语句永远不会执行,这是为什么呢?

标签: c# azure-functions .net-core-3.1 azure-http-trigger


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-19
    • 1970-01-01
    • 2021-06-02
    • 2023-02-01
    相关资源
    最近更新 更多