gottscj / Hangfire.Mongo

Mongo DB support for Hangfire
MIT License
262 stars 84 forks source link

Setting minimum LogLevel to Trace in AddHangfire configuration throws System.MissingMethodException #202

Closed NazmiAltun closed 4 years ago

NazmiAltun commented 5 years ago

When i set minimum loglevel in AddHangfire configuration as below;

services.AddHangfire(config =>
{
    config.UseColouredConsoleLogProvider(Hangfire.Logging.LogLevel.Trace);
}

throws System.MissingMethodException. After setting loglevel back to Debug level, exception no longer occurs. Here is the full details of exception:

System.MissingMethodException: Method not found: 'MongoDB.Bson.BsonDocument MongoDB.Driver.UpdateDefinition1.Render(MongoDB.Bson.Serialization.IBsonSerializer1<!0>, MongoDB.Bson.Serialization.IBsonSerializerRegistry)'.

at Hangfire.Mongo.MongoWriteOnlyTransaction.SerializeWriteModel(WriteModel`1 writeModel) at Hangfire.Mongo.MongoWriteOnlyTransaction.Log() at Hangfire.Mongo.MongoWriteOnlyTransaction.Commit() at Hangfire.RecurringJobManager.AddOrUpdate(String recurringJobId, Job job, String cronExpression, RecurringJobOptions options) at TestOkur.Notification.Startup.UseHangfire(IApplicationBuilder app) at TestOkur.Notification.Startup.Configure(IApplicationBuilder app) at Microsoft.AspNetCore.Mvc.Internal.MiddlewareFilterBuilderStartupFilter.<>cDisplayClass0_0.gMiddlewareFilterBuilder|0(IApplicationBuilder builder) at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.<>cDisplayClass0_0.b0(IApplicationBuilder builder) at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

gottscj commented 5 years ago

@NazmiAltun,

I tried to reproduce in my sample project: Hangfire.Mongo.Sample.AspNetCore.

I use the same configuration

services.AddHangfire(config =>
            {
                // Read DefaultConnection string from appsettings.json
                var connectionString = Configuration.GetConnectionString("DefaultConnection");

                var migrationOptions = new MongoStorageOptions
                {
                    MigrationOptions = new MongoMigrationOptions
                    {
                        Strategy = MongoMigrationStrategy.Migrate,
                        BackupStrategy = MongoBackupStrategy.Collections
                    }
                };
                //config.UseLogProvider(new FileLogProvider());
                config.UseColouredConsoleLogProvider(LogLevel.Trace);
                config.UseMongoStorage(connectionString, "hangfire-mongo-sample-aspnetcore", migrationOptions);
            });

Can you identify any differences betweem the two setups? what Mongo driver version are you using? thanks

NazmiAltun commented 5 years ago

@gottscj Mongo Driver Version 2.9.0 Hangfire.Mongo Version 0.6.3

I call the function as below;

services.AddHangfire(config =>
{
    config.UseColouredConsoleLogProvider(Hangfire.Logging.LogLevel.Trace);
    var migrationOptions = new MongoStorageOptions
    {
        MigrationOptions = new MongoMigrationOptions
        {
            Strategy = MongoMigrationStrategy.Migrate,
            BackupStrategy = MongoBackupStrategy.None,
        },
    };
    config.UseMongoStorage(
        ApplicationConfiguration.ConnectionString,
        $"{ApplicationConfiguration.Database}-Hangfire",
        migrationOptions);
});

Or you can check the source code of entire startup.cs here : https://github.com/testokur/TestOkur.WebApi/blob/master/src/TestOkur.Notification/Startup.cs

gottscj commented 5 years ago

@NazmiAltun,

It looks OK to me. Could you try MongoDriver 2.8.0? I will update to the latest mongo driver in next release

NazmiAltun commented 5 years ago

@gottscj yeah it seems to be working with MongoDriver 2.8.0 .

gottscj commented 5 years ago

@NazmiAltun,

Ok, I will make target the new mongo driver for the next release. else a PR would be greatly appreciated. :)

NazmiAltun commented 5 years ago

@gottscj I can wait for the next release. No rush :) It is not a major issue anyway.