Closed ghost closed 8 months ago
This all works perfectly for me. Is it possible that your IDE is just waiting for some particular terminal output before triggering the opening of a web browser?
If not, running in debug mode and pressing "break" during the hang should reveal what's going on. Keen to hear what you find!
Tested with a brand new minimal api project with only addition of the code below, same problem. This is a debug build and tested both with/without Debugger. However if I add/uncomment WriteTo.Console() then everything starts working as expected. The call stack doesn't reveal anything relevant. Also tried dotnet run through the CLI, same issue.
builder.Host.UseSerilog((context, services, configuration) => configuration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
//.WriteTo.Console()
.WriteTo.Console(new JsonFormatter())
.WriteTo.Console(new CompactJsonFormatter())
.WriteTo.Console(new RenderedCompactJsonFormatter()));
Interesting! Seems like a process of elimination should start narrowing it down - if you remove one WriteTo
block at a time, is one of them in particular a problem?
Yes tested each one of the WriteTo.*JsonFormatter
alone and they all exhibit the same behaviour.
How are you assessing whether or not the process hangs? Can you send a web request to the API? If not, what's the behavior?
These are extremely widely-used components with otherwise fairly simple string formatting code in them, so it's unlikely the issue is a simple/direct one. It's more than likely an environmental problem so unfortunately you'll be the only one able to solve this (it's not possible for me without me being able to repro the issue).
Stepping through start-up in the debugger, with "break on all exceptions" enabled, is the way to go I think.
Thanks for the tip, was able to hit Swagger successfully from the browser. Finally made a breakthrough using the info below. Its the way VSCode is matching the url to launch the browser and because we're logging JSON the match is failing hence the reason it works with WriteTo.Console()
. Thanks a lot for this awesome library. Will close this as resolved.
Description While trialing out TraceId and SpanId support on a new Controllers API project I found that the commented out lines of code when enabled are causing the webapi process from running further. It prints a bunch of messages then hangs and Swagger does not show up anymore. However if the code is commented out then everything runs happily and Swagger is shown as per normal and TraceId and SpanId are also printed out as expected.
Reproduction
Expected behavior Logging should just continue as normal without hanging the process.
Relevant package, tooling and runtime versions
Additional context