Capturing errors in hosted Blazor Web Assembly app

227 views Asked by At

I have a .net Hosted Blazor Web Assembly app (the one that generates 3 projects, Client (Blazor Web Assembly project), Server (Web API Server project), Shared.

How can I log errors on the server app? In regular .net Core apps I'd add something like this to the web.config for it to store errors in the Logs folder:

<aspNetCore arguments="" stdoutLogEnabled="true" hostingModel="InProcess" stdoutLogFile=".\logs\stdout">
</aspNetCore>

However, this doesn't work in the web.config file that Publish generates in the hosted Blazor app.

I found this file, but it doesn't suggest how to debug the Server project on the server: https://learn.microsoft.com/en-us/aspnet/core/blazor/debug?view=aspnetcore-6.0&tabs=visual-studio

I've googled this and can't find how to get the errors from the Server app. Ideally some kind of error emailed to me would be ideal but logs in a folder would be OK.

Thanks

1

There are 1 answers

2
Nb777 On

You need to use some third party library like NLog.
Blazor server log works exactly like Asp.net core. See this link about using Nlog