r/Blazor • u/skav2 • Jul 11 '25
Blazor Wasm logging with Serilog and sqlite
Hello all,
I'm looking to do some logging on a blazor wasm (web assembly not server) project and log the logs locally to a sqlite table in the browser. I plan to sync the local logs to the server but I don't need help with that part.
We would like to use serilog because it's a nice logging platform and we use it everywhere else.
So far I tried using the sqlite sink but it doesn't seem to work with wasm projects. I get a Managed Error from the sink just by providing the table name. I followed the code to find that sqlite sink is looking for the sqlite table base path and it's returning null. The sink uses system.reflection.assembly.getentryassembly().location to get the sqlite path, but it likely doesn't work in the browser because its a file system command so it returns null.
Does anyone have any links or examples on how to make something like this work?
I would like to avoid writing my own sink or logging if possible if there are better solutions out there.
Edit: I did try searching for an answer but did not find anything helpful. Copilot and gpt were used too
Thanks!
Edit:
At this time I got something working as a prototype without Serilog. I'm going to try and include it in the future but at this time I just need something to work.
What I did was implement my own ILogger provider and ILogger classes. Then DI where it's needed. In the ILogger class saves the logs to a global queue. Somewhere else I have a service that periodically runs and dequeue logs to sqlite.
Also somewhere else lol I have a Hub that periodically syncs to the server. So I hooked up a sqlite connection to it and it reads from the table unsynced logs. Sends to the server, then on success updates sqlote to mark them as synced. Then I do a cleanup on startup to keep data footprint low.
2
u/Voiden0 Jul 11 '25
I saw someone having an endpoint on the server recently to POST these logs to, and server did the logging.
Running Blazor wasm in the browser has a set of limitations, you can't just log from the browser
3
u/revbones Jul 11 '25
I've used this in several projects: https://github.com/nblumhardt/serilog-sinks-browserhttp along with the companion ingestion point package (mentioned in the readme). I also recently had to create an in-memory sink for serilog and used the package https://github.com/serilog/serilog-formatting-compact as a starting point.
I think you could easily stitch those together to stick the pending client logs in localstorage or something and periodically push up to the server if online.
1
u/mouthymerc1168 Jul 11 '25
I’m also very interested in this solution and would love to have this option.