Custom logging to app insights from .net core

Slicc

I'm using App Insights in a .net core web app and I can successfully see the telemetry data in the app insights logs. I would now like to be able to push up my own log events, but cannot seem to get it to work (i.e. my custom log events do not appear in app insights). My code is as follows:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    loggerFactory.AddApplicationInsights(app.ApplicationServices);
    loggerFactory.AddDebug();

    var logger = loggerFactory.CreateLogger<Startup>();

    logger.LogInformation("I am a log event");

I've also tried setting the log level explicitly like:

loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Debug);

But I never see the text "I am a log event" in app insights.

Can anyone tell me how I can fix this?

Set
  1. You need to add an Application Insights log capture module for that. Select the appropriate package - one of:
    • Microsoft.ApplicationInsights.TraceListener (to capture System.Diagnostics.Trace calls)
    • Microsoft.ApplicationInsights.EventSourceListener (to capture EventSource events)
    • Microsoft.ApplicationInsights.EtwListener (to capture ETW events)
    • Microsoft.ApplicationInsights.NLogTarget
    • Microsoft.ApplicationInsights.Log4NetAppender

Documentation section: Explore .NET trace logs in Application Insights

  1. Also, you may use TelemetryClient directly. It has more options, not only TrackTrace that is used by loggers.
//TelemetryClient telemetryClient = new Microsoft.ApplicationInsights.TelemetryClient();
...
telemetryClient.TrackEvent("<EventName>");
telemetryClient.TrackMetric("<metric name>", 1);
telemetryClient.TrackTrace("message", SeverityLevel.Information);

Documentation section: Application Insights API for custom events and metrics

For the live example, you may look into feature test int ApplicationInsights-aspnetcore repo.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Disabling dependency logging for Application insights on Azure app service (Web app)

分類Dev

Inject App Insights for Custom Events and Metrics

分類Dev

Referencing .NET 4.6.2 class library from .NET Core app

分類Dev

Application Insights in Net Core 2 WebApi - Share Context To Append Properties

分類Dev

Python logging: No output from custom logger

分類Dev

Web API + Azure App Insights pass the data from ActionFilter to ITelemetryProcessor

分類Dev

invoke an action if asynchronous logging is failed in asp.net core

分類Dev

Exectute a Linux Shell command from ASP.NET Core 3 app

分類Dev

Can't connect to SQL Server express from .net core app running on docker

分類Dev

Store / Retrieve ConnectionString from appSettings.json in ASP.net Core 2 MVC app

分類Dev

Using Azure Active Directory authentication in ASP.NET Core 2.0 from Web App to Web API

分類Dev

.Net core App unable to get user details from Microsoft Graph API?

分類Dev

.NET Core MVC web app gets value from query string instead of Model

分類Dev

Ignore timezone when posting value from Angular app to .Net Core WebAPI

分類Dev

Testing zap logging for a Logger built from a custom Config

分類Dev

How to implement Custom Model Validator in .NET Core

分類Dev

Application Insights logging provider not working in AspNetCore 2.0

分類Dev

Azure Application Insights - Disable Logging Page Views

分類Dev

Running PowerShell from .NET Core

分類Dev

Running PowerShell from .NET Core

分類Dev

.NET Core 3.1 Console App as a Windows Service

分類Dev

Deploy ASP.NET Core 5 app to Azure App Service?

分類Dev

Deploy ASP.NET Core 5 app to Azure App Service?

分類Dev

Azure App InsightsのFlush()

分類Dev

Launch QT App from Custom Protocol - Windows

分類Dev

NLog asp.net core sends email automatically on error without logging it

分類Dev

NLog asp.net core sends email automatically on error without logging it

分類Dev

Logging in Google App Script

分類Dev

Is it possible to use a custom ModelState validation provider in ASP.NET Core?

Related 関連記事

  1. 1

    Disabling dependency logging for Application insights on Azure app service (Web app)

  2. 2

    Inject App Insights for Custom Events and Metrics

  3. 3

    Referencing .NET 4.6.2 class library from .NET Core app

  4. 4

    Application Insights in Net Core 2 WebApi - Share Context To Append Properties

  5. 5

    Python logging: No output from custom logger

  6. 6

    Web API + Azure App Insights pass the data from ActionFilter to ITelemetryProcessor

  7. 7

    invoke an action if asynchronous logging is failed in asp.net core

  8. 8

    Exectute a Linux Shell command from ASP.NET Core 3 app

  9. 9

    Can't connect to SQL Server express from .net core app running on docker

  10. 10

    Store / Retrieve ConnectionString from appSettings.json in ASP.net Core 2 MVC app

  11. 11

    Using Azure Active Directory authentication in ASP.NET Core 2.0 from Web App to Web API

  12. 12

    .Net core App unable to get user details from Microsoft Graph API?

  13. 13

    .NET Core MVC web app gets value from query string instead of Model

  14. 14

    Ignore timezone when posting value from Angular app to .Net Core WebAPI

  15. 15

    Testing zap logging for a Logger built from a custom Config

  16. 16

    How to implement Custom Model Validator in .NET Core

  17. 17

    Application Insights logging provider not working in AspNetCore 2.0

  18. 18

    Azure Application Insights - Disable Logging Page Views

  19. 19

    Running PowerShell from .NET Core

  20. 20

    Running PowerShell from .NET Core

  21. 21

    .NET Core 3.1 Console App as a Windows Service

  22. 22

    Deploy ASP.NET Core 5 app to Azure App Service?

  23. 23

    Deploy ASP.NET Core 5 app to Azure App Service?

  24. 24

    Azure App InsightsのFlush()

  25. 25

    Launch QT App from Custom Protocol - Windows

  26. 26

    NLog asp.net core sends email automatically on error without logging it

  27. 27

    NLog asp.net core sends email automatically on error without logging it

  28. 28

    Logging in Google App Script

  29. 29

    Is it possible to use a custom ModelState validation provider in ASP.NET Core?

ホットタグ

アーカイブ