datalust/serilog-sinks-seq

Upgrading to 5.2 from 5.1 breaks use in Blazor WebAssembly

vincentnl opened this issue · 11 comments

Downgrading fixed the issue.

The Chrome console reports:
System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Net.Http.SocketsHttpHandler.set_PooledConnectionLifetime(TimeSpan value)
at Serilog.Sinks.Seq.Http.SeqIngestionApiClient..ctor(String serverUrl, String apiKey, HttpMessageHandler messageHandler)
at Serilog.SeqLoggerConfigurationExtensions.Seq(LoggerSinkConfiguration loggerSinkConfiguration, String serverUrl, LogEventLevel restrictedToMinimumLevel, Int32 batchPostingLimit, Nullable1 period, String apiKey, String bufferBaseFilename, Nullable1 bufferSizeLimitBytes, Nullable1 eventBodyLimitBytes, LoggingLevelSwitch controlLevelSwitch, HttpMessageHandler messageHandler, Nullable1 retainedInvalidPayloadsLimitBytes, Int32 queueSizeLimit)

Log.Logger = new LoggerConfiguration() .MinimumLevel.Override("Microsoft", LogEventLevel.Information) .Enrich.FromLogContext() .Enrich.WithProperty("Domain", "PersonalFinance") .Enrich.WithProperty("App", "Web") //.WriteTo.BrowserConsole() // this one causes Json errors (null value) //.WriteTo.Debug() .WriteTo.Seq("http://****.org:5341") .CreateLogger();

Hi @vincentnl,

Thanks for the report. This issue occurs because Blazor WASM doesn't use the .NET HttpClient, but instead wraps the browsers fetch API. Use of HttpClient features that can't be mapped to fetch result in exceptions.

It is probable that 5.2 will work with net6.0 if you are able to target that.

Thanks @vincentnl,
We have reproduced the error. Now we just need to fix it. :)

Hi @vincentnl - 5.2.1-dev-00245 should have this covered now but is not yet tested - if you have a chance to try it out and let us know how you go, we should be able to push this to a stable release shortly. HTH!

On .NET 6.0.10 Blazor WASM I get this using v5.2.1:

System.AggregateException: One or more errors occurred. (Operation is not supported on this platform.)
 ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.Net.Http.SocketsHttpHandler.set_PooledConnectionLifetime(TimeSpan value)
   at Serilog.Sinks.Seq.Http.SeqIngestionApiClient..ctor(String serverUrl, String apiKey, HttpMessageHandler messageHandler)
   at Serilog.SeqLoggerConfigurationExtensions.Seq(LoggerSinkConfiguration loggerSinkConfiguration, String serverUrl, LogEventLevel restrictedToMinimumLevel, Int32 batchPostingLimit, Nullable`1 period, String apiKey, String bufferBaseFilename, Nullable`1 bufferSizeLimitBytes, Nullable`1 eventBodyLimitBytes, LoggingLevelSwitch controlLevelSwitch, HttpMessageHandler messageHandler, Nullable`1 retainedInvalidPayloadsLimitBytes, Int32 queueSizeLimit)
   at CPCA.CpcaLogging.AddSeq(LoggerConfiguration loggerConfig, Seq seq, LoggingLevelSwitch levelSwitch) in D:\Source\CPCAv4\source\CPCA.Infrastructure.Logging\CpcaLogging.cs:line 70
   at CPCA.CpcaLogging.ConfigureLogging[CpcaClientModule](IServiceCollection services, IConfiguration configuration, LoggerConfiguration loggerConfig) in D:\Source\CPCAv4\source\CPCA.Infrastructure.Logging\CpcaLogging.cs:line 36
   at CPCA.Presentation.Client.ServiceCollectionExtensions.AddCpcaLogging(WebAssemblyHostBuilder builder) in D:\Source\CPCAv4\source\CPCA.Presentation.Client\ServiceCollectionExtensions.cs:line 132
   at CPCA.Presentation.Client.Program.Main(String[] args) in D:\Source\CPCAv4\source\CPCA.Presentation.Client\Program.cs:line 28
   --- End of inner exception stack trace ---

The line in question is:

loggerConfig.WriteTo.Seq(serverUrl: seq.ServerUrl, apiKey: seq.ApiKey, controlLevelSwitch: levelSwitch);

Hi @hellfirehd ,

I think you might need the more recent 5.2.1-dev-00245 .

As to your request, I've updated to 5.2.1-dev-00247 - Support on Blazor Wasm is not yet working.

System.AggregateException: One or more errors occurred. (Operation is not supported on this platform.)
---> System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Net.Http.SocketsHttpHandler.set_PooledConnectionLifetime(TimeSpan value)
at Serilog.Sinks.Seq.Http.SeqIngestionApiClient..ctor(String serverUrl, String apiKey, HttpMessageHandler messageHandler)
at Serilog.SeqLoggerConfigurationExtensions.Seq(LoggerSinkConfiguration loggerSinkConfiguration, String serverUrl, LogEventLevel restrictedToMinimumLevel, Int32 batchPostingLimit, Nullable1 period, String apiKey, String bufferBaseFilename, Nullable1 bufferSizeLimitBytes, Nullable1 eventBodyLimitBytes, LoggingLevelSwitch controlLevelSwitch, HttpMessageHandler messageHandler, Nullable1 retainedInvalidPayloadsLimitBytes, Int32 queueSizeLimit)
at Web.Program.Main(String[] args) in E:\Personal Finance\Web\Program.cs:line 29
--- End of inner exception stack trace ---

I'll take another look - thanks for checking it out, everyone :-)

Sorry, just in case you beat me to it - 5.2.2-dev-00247 is the version with the fix; the bug is in all earlier 5.2.x versions. I misstated the fix version in my earlier message, sorry.

I've tested with 5.2.2-dev-00247.

Sorry to report that it has not been resolved.

blazor.webassembly.js:1 System.AggregateException: One or more errors occurred. (Operation is not supported on this platform.)
 ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.Net.Http.SocketsHttpHandler.set_PooledConnectionLifetime(TimeSpan value)
   at Serilog.Sinks.Seq.Http.SeqIngestionApiClient..ctor(String serverUrl, String apiKey, HttpMessageHandler messageHandler)
   at Serilog.SeqLoggerConfigurationExtensions.Seq(LoggerSinkConfiguration loggerSinkConfiguration, String serverUrl, LogEventLevel restrictedToMinimumLevel, Int32 batchPostingLimit, Nullable`1 period, String apiKey, String bufferBaseFilename, 
Nullable`1 bufferSizeLimitBytes, Nullable`1 eventBodyLimitBytes, LoggingLevelSwitch controlLevelSwitch, HttpMessageHandler messageHandler, Nullable`1 retainedInvalidPayloadsLimitBytes, Int32 queueSizeLimit)
   at Web.Program.Main(String[] args) in E:\xxxxx\Program.cs:line 30
   --- End of inner exception stack trace ---
callEntryPoint @ blazor.webassembly.js:1
await in callEntryPoint (async)
Vt @ blazor.webassembly.js:1
await in Vt (async)
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1

My configuration is still the same:

Log.Logger = new LoggerConfiguration()
        .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
        .Enrich.FromLogContext()
        .Enrich.WithProperty("Domain", "PersonalFinance")
        .Enrich.WithProperty("App", "Web")
        .WriteTo.BrowserConsole()
            .Filter.ByExcluding(Matching.FromSource<CustomAuthStateProvider>())
        .WriteTo.Seq("http://xxx:5341")
        .CreateLogger();

Thanks for checking it out again @vincentnl . I've had another attempt and verified with a sample project in:

#191

I'll let you know here as soon as there's a published build available. Thanks again!