Filepath in Serilog for WebAssembly contains /

John Lee 21 Reputation points
2021-11-22T20:14:08.003+00:00

Strange thing. Trying to configure Serilog for my Blazor WebAssembly app. There was no log file being created. The same configuration code is used in Blazor server app works fine.
The WebAssembly app uses SeriLog.Sinks.File while the server app uses Serilog.AspNetCore
var loggerConfiguration = new LoggerConfiguration()
.Enrich.WithProperty("Host", host)
.Enrich.WithProperty("Version", appVersion)
.Enrich.WithProperty("logger", appName)
.Enrich.WithProperty("thread", threadId)
.Enrich.WithProperty("Pid", pid)
.WriteTo.Console(outputTemplate: logAppenderConfig.OutputTemplate, levelSwitch: levelSwitch)
.WriteTo.File(
path: fqn,
restrictedToMinimumLevel: logAppenderConfig.EventLevel,
outputTemplate: logAppenderConfig.OutputTemplate,
fileSizeLimitBytes: logAppenderConfig.MaxFileSize,
levelSwitch: levelSwitch,
rollingInterval: RollingInterval.Day,
retainedFileCountLimit: logAppenderConfig.RetentionCount,
rollOnFileSizeLimit: true
);
When I look at the loggerConfiguration in the debugger, I noticed that roller._directory = /
151430-image.png

The file name then also starts with /, which doesn't work well with Windows.
151582-image.png

Developer technologies | .NET | Blazor
{count} votes

Answer accepted by question author
  1. Bruce (SqlWork.com) 82,146 Reputation points Volunteer Moderator
    2021-11-23T16:27:14.017+00:00

    Serilog has a console sink for blazor webassembly

    https://github.com/serilog/serilog-sinks-browserconsole

    as suggested, there is no file support in Blazor/WASM

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.