Description
I've spent the better part of 2 days on the following issue and I'm running out of ideas. Hopefully someone has had a similar experience and can help me out.
I have a .NET 8.0 iOS, Windows, and Android app with a shared backend. Serilog exception logging to application insights is working perfectly for iOS and Windows, but it only works for Android in the DEBUG configuration of my app.
Reproduction
instantiating the telemetry client during app start:
var telemetryConfiguration = TelemetryConfiguration.CreateDefault();
var telemetryConnection = config["ApplicationInsightsConnection"];
if (string.IsNullOrEmpty(telemetryConnection))
{
throw new InvalidOperationException("The required configuration value 'ApplicationInsightsConnection' was not configured in
appsettings.json");
}
telemetryConfiguration.ConnectionString = telemetryConnection;
var telemetryClient = new TelemetryClient(telemetryConfiguration);
Mvx.IoCProvider.RegisterSingleton(telemetryClient);
Setting up the serilogger configuration:
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Async(a => a.AndroidLog())
.WriteTo.ApplicationInsights(iocProvider.Resolve<TelemetryClient>(),
TelemetryConverter.Events).CreateLogger();
Writing an exception (where _platformSpecificLogger is an instance of SeriLog implementing ILogger)
_platformSpecificLogger?.LogError(exception, $"{message}, {toAppend}", toAppend);
ONLY In case the exception is unhandled we finalize with this in de Android project:
private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Exception exception = e.ExceptionObject as Exception ?? new Exception($"{nameof(UnhandledExceptionEventArgs)}.
{nameof(e.ExceptionObject)} is not of type Exception; {e.ExceptionObject}");
HandleException(exception);
// Makes sure serilog sends application insights telemetry before the application terminates.
**Serilog.Log.CloseAndFlush();**
}
Expected behavior
On Android, after compiling my app in Release Mode, I expect exceptions logged by Serilog to be visible in Application insights.
Relevant package, tooling and runtime versions
The relevant setup:
Serilog version 4.0.1
Serilog app insights version 4.0.0
Application insights version 2.22.0
Platform: .Net 8 app, Android (no Maui).
Additional Context
- Serilog throws no exceptions and all the logger, telemetryClient, connection string etc. are all properly instantiated and have correct values.
- Turning off code optimalization options in .csproj (like linking) in Release mode makes no difference.
- Directly sending Telemetry via the telemetry client instance DOES work, also in release mode.
- I want to stretch that I do exactly the same thing for the Windos and iOS apps. In those cases, the Exceptions do arrive in application insights. Also in release mode.
- Size of the exception makes no difference. It doesn't arrive in application insights even if I do: throw new Exception("test").
Description
I've spent the better part of 2 days on the following issue and I'm running out of ideas. Hopefully someone has had a similar experience and can help me out.
I have a .NET 8.0 iOS, Windows, and Android app with a shared backend. Serilog exception logging to application insights is working perfectly for iOS and Windows, but it only works for Android in the DEBUG configuration of my app.
Reproduction
instantiating the telemetry client during app start:
Setting up the serilogger configuration:
Writing an exception (where _platformSpecificLogger is an instance of SeriLog implementing ILogger)
_platformSpecificLogger?.LogError(exception, $"{message}, {toAppend}", toAppend);
ONLY In case the exception is unhandled we finalize with this in de Android project:
Expected behavior
On Android, after compiling my app in Release Mode, I expect exceptions logged by Serilog to be visible in Application insights.
Relevant package, tooling and runtime versions
The relevant setup:
Serilog version 4.0.1
Serilog app insights version 4.0.0
Application insights version 2.22.0
Platform: .Net 8 app, Android (no Maui).
Additional Context