serilog-contrib / serilog-sinks-applicationinsights

A Serilog sink that writes events to Microsoft Azure Application Insights
Apache License 2.0
220 stars 72 forks source link

Question: How do you flush with config files? #178

Closed scottkuhl closed 2 years ago

scottkuhl commented 2 years ago

The readme instructions indicate you should flush the telemetry client:

var log = new LoggerConfiguration().WriteTo.ApplicationInsights(_telemetryClient, TelemetryConverter.Events).CreateLogger();
...
_telemetryClient.Flush();

If you are configuring AI through config files, how do you get the reference to the telemetry client in order to flush it?

Example:

Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(builder.Configuration).CreateLogger();
try
{
...
}
catch (Exception ex)
{
    Log.Fatal(ex, "Host terminated unexpectedly.");
}
finally
{
    Log.CloseAndFlush();
}
nblumhardt commented 2 years ago

Hi Scott - thanks for your question. After a change in maintainers I'm running through and cleaning up unanswered questions/old issues. If you were able to figure out a solution here it would be great to know - otherwise, it might be necessary to propose this on Stack Overflow as I don't personally have an answer, sorry. HTH!