Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceptions showing up as type TextException #24

Open
JasonLooney opened this issue Jan 18, 2024 · 1 comment
Open

Exceptions showing up as type TextException #24

JasonLooney opened this issue Jan 18, 2024 · 1 comment

Comments

@JasonLooney
Copy link

We're using these libraries to send log messages from a Blazor WebAssembly app up to an ASP.NET server in Azure, which in turn logs to ApplicationInsights. However, all exceptions coming from the client are showing up as the type TextException in the logs and are missing the exception details.

How can we fix this?

On the client, our logger is configured like so:

Log.Logger = new LoggerConfiguration()
    .MinimumLevel.ControlledBy(levelSwitch)
    .Enrich.WithProperty("InstanceId", Guid.NewGuid().ToString("n"))
    .WriteTo.BrowserHttp(controlLevelSwitch: levelSwitch, endpointUrl: $"{builder.HostEnvironment.BaseAddress}ingest")
    .CreateLogger();

And on the server:

builder.Host.UseSerilog((context, services, configuration) => configuration
    .ReadFrom.Configuration(context.Configuration)
    .ReadFrom.Services(services)
    .Enrich.FromLogContext()
    .WriteTo.ApplicationInsights(new TelemetryConfiguration { ConnectionString = appInsightsConnection }, TelemetryConverter.Traces));

// ...

webApp.UseSerilogIngestion();
webApp.UseSerilogRequestLogging();
@nblumhardt
Copy link
Owner

Hi Jason,

TextException is this class from Serilog.Formatting.Compact.Reader.

On the client side, exceptions are captured using ToString(), and the result ends up wrapped in a TextException server-side.

The only way you should see TextException appear anywhere is some code going to the exception's Type directly; most Serilog sinks etc. won't do that, and instead use ToString(), which for these exceptions will show the original type/stack trace/message.

My guess is there's something in the App Insights sink responsible for this; if you spot it and need help figuring out a workaround, let me know.

Hope this helps,
Nick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants