You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
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").
The text was updated successfully, but these errors were encountered:
Thomas-Slippens
changed the title
Exception are not logged to application insights for an Android app in Release configuration
Exceptions are not logged to application insights for an Android app in Release configuration
Aug 28, 2024
Hi @Thomas-Slippens - unfortunately only a very limited number of maintainers watch this repository, and it doesn't look like anyone immediately spotted the problem here. Posting this to Stack Overflow with the serilog tag should get more eyes on it. Best of luck!
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
The text was updated successfully, but these errors were encountered: