Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to cast object of type 'Serilog.Sinks.Graylog.Batching.PeriodicBatchingGraylogSink' to type 'Serilog.Core.ILogEventSink' #97

Open
cubed-it opened this issue Jun 26, 2023 · 5 comments

Comments

@cubed-it
Copy link

cubed-it commented Jun 26, 2023

Hey there, I have just upgraded to 3.0.1 and was wondering about the following error:

Unhandled exception. System.InvalidCastException: Unable to cast object of type 'Serilog.Sinks.Graylog.Batching.PeriodicBatchingGraylogSink' to type 'Serilog.Core.ILogEventSink'.
   at Serilog.Sinks.Graylog.Batching.LoggerConfigurationGrayLogExtensions.Graylog(LoggerSinkConfiguration loggerSinkConfiguration, BatchingGraylogSinkOptions options)

Thanks!

@da9l
Copy link

da9l commented Aug 2, 2023

I've encountered the same problem during runtime.

A strange thing I see in the code is:
https://github.com/whir1/serilog-sinks-graylog/blob/01d4630424120db1ea21de35c33cd2feb47915a6/src/Serilog.Sinks.Graylog.Batching/LoggerConfigurationGrayLogExtensions.cs#L22

The PeriodicBatchingGraylogSink that implements IBatchedLogEventSink is being casted to the unrelated (!?!) ILogEventSink.
My day gig language is not C# so I'm not sure when this is expected to work (if all..)

    public static class LoggerConfigurationGrayLogExtensions
    {
       ///...
        public static LoggerConfiguration Graylog(this LoggerSinkConfiguration loggerSinkConfiguration,
                                                  BatchingGraylogSinkOptions options)
        {
            var sink = (ILogEventSink)new PeriodicBatchingGraylogSink(options);
            return loggerSinkConfiguration.Sink(sink, options.MinimumLogEventLevel);
        }

I'd say the bug is introduced in 3.0.0. The PeriodicBatchingGraylogSink class is not tested so this bug should be possible to expose with a creation test.
Downgrading this nupkg to 1.3.0 seems to be an acceptable workaround.

@danielwertheim
Copy link

@danielwertheim
Copy link

@whir1

Is it supposed to be something in the lines of this?

var sink = new PeriodicBatchingSink(new PeriodicBatchingGraylogSink(options), new PeriodicBatchingSinkOptions
{
    BatchSizeLimit = options.BatchSizeLimit,
    QueueLimit = options.QueueLimit,
    Period = options.Period,
});

return loggerSinkConfiguration.Sink(sink, options.MinimumLogEventLevel);

@danielwertheim
Copy link

Also, why has it been locked to UDP? When applying the workaround above in own extension method it didn't use HTTP that I configure it to via config.

Found this: https://github.com/whir1/serilog-sinks-graylog/blob/master/src/Serilog.Sinks.Graylog.Batching/LoggerConfigurationGrayLogExtensions.cs#L85

Hardcoded to UDP.

@danielwertheim
Copy link

Also, why has it been locked to UDP? When applying the workaround above in own extension method it didn't use HTTP that I configure it to via config.

Found this: https://github.com/whir1/serilog-sinks-graylog/blob/master/src/Serilog.Sinks.Graylog.Batching/LoggerConfigurationGrayLogExtensions.cs#L85

Hardcoded to UDP.

This seems to have been solved at least. Maybe other issues as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants