admin管理员组

文章数量:1122846

I have an Azure function

  • I created application insight resource when creating Function App
  • Azure function has registered Insights telemetry by default

Environment variable in Azure Portal (default)

Program.cs (default)

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureServices(services =>
    {
        services.AddApplicationInsightsTelemetryWorkerService();
        services.ConfigureFunctionsApplicationInsights();
    })
    .Build();

Function Logs in Azure Portal console

Function Logs in Logs workspace

The issue and question is, why I see the following logs in Azure Portal Log Console

 _logger.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

but not in Logs workspace?

Any idea?

Update 1:

I verified that the application insight is connected to function app

Log levels are set to information: host.json

{
  "version": "2.0",
  "logging": {
    "LogLevel": {
      "Default": "Information"
    },
    "applicationInsights": {
      "LogLevel": {
        "Default": "Information"
      },
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request;Exception"
      },
      "enableLiveMetricsFilters": true
    }
  }
}

Update 2:

_logger.LogInformation("[Http Triggered Function] Information.");
_logger.LogWarning("[Http Triggered Function] Warning.");
_logger.LogError("[Http Triggered Function] Error.");

Warning and errors are logged correctly

Update 3

Seems like host.json configuration is not taking into account at all. If I want to log only errors

{
  "version": "2.0",
  "logging": {
    "LogLevel": {
      "Default": "Error",
      "Function": "Error",
      "Function.Function1": "Error",
      "Function.ChangeTrackingFunction": "Error"
    },
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  }
}

Warning are still being logged into console and into Logs workspace.

I have an Azure function

  • I created application insight resource when creating Function App
  • Azure function has registered Insights telemetry by default

Environment variable in Azure Portal (default)

Program.cs (default)

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureServices(services =>
    {
        services.AddApplicationInsightsTelemetryWorkerService();
        services.ConfigureFunctionsApplicationInsights();
    })
    .Build();

Function Logs in Azure Portal console

Function Logs in Logs workspace

The issue and question is, why I see the following logs in Azure Portal Log Console

 _logger.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

but not in Logs workspace?

Any idea?

Update 1:

I verified that the application insight is connected to function app

Log levels are set to information: host.json

{
  "version": "2.0",
  "logging": {
    "LogLevel": {
      "Default": "Information"
    },
    "applicationInsights": {
      "LogLevel": {
        "Default": "Information"
      },
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request;Exception"
      },
      "enableLiveMetricsFilters": true
    }
  }
}

Update 2:

_logger.LogInformation("[Http Triggered Function] Information.");
_logger.LogWarning("[Http Triggered Function] Warning.");
_logger.LogError("[Http Triggered Function] Error.");

Warning and errors are logged correctly

Update 3

Seems like host.json configuration is not taking into account at all. If I want to log only errors

{
  "version": "2.0",
  "logging": {
    "LogLevel": {
      "Default": "Error",
      "Function": "Error",
      "Function.Function1": "Error",
      "Function.ChangeTrackingFunction": "Error"
    },
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  }
}

Warning are still being logged into console and into Logs workspace.

Share Improve this question edited Dec 11, 2024 at 0:10 Muflix asked Nov 21, 2024 at 17:24 MuflixMuflix 6,75819 gold badges92 silver badges170 bronze badges 2
  • The original post mentions that logs are not being sent to the Log Analytics workspace. However, according to update 3, you only want to log errors, not warnings, into the Log Analytics workspace. Is that correct? – SKARVA Bodavula Commented Nov 28, 2024 at 2:21
  • Hello @SKARVABodavula, no, the host.json seems to be not applied at all. I would like to log all logs but the information logs are not available in the application insight logs, but printed only into the console. – Muflix Commented Nov 29, 2024 at 15:54
Add a comment  | 

1 Answer 1

Reset to default 1

In the Logs workspace of your Azure Function, if custom logs are absent, check these most likely culprits: There are a few possible explanations for this:

Logging Configuration: Make sure that logging is configured in the Azure Function App that you are using. Use the Azure portal settings to verify that Application Insights has been set.

Log Levels: Ensure that your function code invokes logs at the right log levels. If Node.js is your choice, for example, console.log() should be used at the Information level or higher. In Python, make use of print() statements as needed.

Diagnostic Settings: Find out if you have turned on diagnostic settings for your Function App. In the absence of these settings, logs are unlikely to be transmitted to the Log Analytics workspace. They can indeed be activated in Azure portal under the “Monitoring” tab of your Function App.

Application Insights Integration: You need to confirm that your Function App has been integrated with Application Insights. Lack of or an erroneous instrumentation key or connection string means the log may not be transmitted to Application Insights and hence not show in the Logs workspace.

本文标签: Why I don39t see Azure Function Information logs in Logs workspaceStack Overflow