datalust / serilog-sinks-seq

A Serilog sink that writes events to the Seq structured log server
https://datalust.co/seq
Apache License 2.0
225 stars 50 forks source link

Upgrading to 5.2 from 5.1 breaks use in Blazor WebAssembly #184

Closed vincentnl closed 1 year ago

vincentnl commented 2 years ago

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();

liammclennan commented 2 years ago

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.

vincentnl commented 2 years ago

Dear Liam,

Thank you for the quick feedback. I’m aware that I submit a poorly documented issue, with low reproducibility and context information. As I’m well served with downgrading to 5.1, my issue is resolved, for now.

As to your suggestion, I’m already targeting .net 6.0, so not sure if that is the solution.

liammclennan commented 2 years ago

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

nblumhardt commented 1 year ago

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!

hellfirehd commented 1 year ago

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);
liammclennan commented 1 year ago

Hi @hellfirehd ,

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

vincentnl commented 1 year ago

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 ---

nblumhardt commented 1 year ago

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

nblumhardt commented 1 year ago

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.

vincentnl commented 1 year ago

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();
nblumhardt commented 1 year ago

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

https://github.com/datalust/serilog-sinks-seq/pull/191

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