@rikbosch thank you, you saved my day!
This is a nice situation. Initial thought was to remove the need to upgrade current project dependencies to latest versions to use Hangfire. This decision works perfectly with
Newtonsoft.Json package, but failed for
Common.Logging. So, some action required for logging subsystem in Hangfire.
Continue to use Common.Logging 2.2.0
This seem as a reasonable solution unless some other package you use in your application depends on the latest version. In that case you will be unable to use Hangfire, so it is unacceptable to continue to use the old version.
Upgrade Common.Logging to the latest version
This step will require additional actions for Hangfire users as they need to update some other packages (for example,
Common.Logging.NLog) in order to use the latest package version. The trouble is that other Hangfire packages (
Hangfire.PostgreSql) depend on the old version of
Common.Logging package, and they should be re-released.
After upgrading, we may have the same problems in future.
Change Hangfire to use LibLog
A single file for you to either copy/paste or install via nuget, into your library/framework/application to enable dependency free logging. It contains transparent built-in support for NLog, Log4Net, EntLib Logging, Serilog and Loupe or allows the user to define a custom provider.
-- LibLog readme
So, if you use one of the logging library mentioned above, you don't need to install anything else, it just works. If you have other logging provider, all you need is to implement two simple interfaces:
public interface ILogProvider
ILog GetLogger(string name);
public interface ILog
bool Log(LogLevel logLevel, Func<string> messageFunc);
void Log<TException>(LogLevel logLevel, Func<string> messageFunc, TException exception) where TException : Exception;
This step will require to do the following things:
- Replace all references to
Common.Logging API with the new logging provider in all Hangfire projects using Common.Logging.
- Implement interfaces described above for target projects if required, or at least remove the
LogManager.Adapter = /* ... */ line in the project.
Actions described above are similar to actions required to do after upgrading the
Common.Logging version to the latest one, so it seems reasonable to me to perform the switch to the
LibLog as soon as possible.