0

I have an existing asp.net Web api project. this project is using Serilog for logging. Using OwinStartup it is configuring Serilog like this

var logger = new LoggerConfiguration()
            .ReadFrom.AppSettings()
            .CreateLogger();

        logger.Information("Api Startup");

and AppSettings has bunch of settings.

instance is also registered like this

        builder.RegisterInstance(logger).As<ILogger>().SingleInstance().PropertiesAutowired();

i there a way i can replace this serilog implementation with app insights or somehow use it together so all the logs goes inside app Insights and not in file system as configured right now.

Raas Masood
  • 1,475
  • 3
  • 23
  • 61

1 Answers1

0

Just use the package Serilog.Sinks.ApplicationInsights and add AppInsights as a sink for Serilog

var log = new LoggerConfiguration()
    .WriteTo
    .ApplicationInsights(TelemetryConfiguration.Active, TelemetryConverter.Traces)
    .CreateLogger();

https://github.com/serilog/serilog-sinks-applicationinsights

silent
  • 14,494
  • 4
  • 46
  • 86