I starting hangfire server
Hangfire.GlobalConfiguration.Configuration.UseSqlServerStorage(Constants.ConnectionString, new SqlServerStorageOptions
{
PrepareSchemaIfNecessary = false,
QueuePollInterval = TimeSpan.FromSeconds(15)
});
app.UseHangfireDashboard();
after that log4net stop writing logs
Wasn't able to reproduce. Can you create a GitHub repository that reproduces the problem?
https://github.com/timurabdurafeev/HangfireLog4netConflict
GlobalConfiguration.Configuration.UseSqlServerStorage("Data Source=(local);Initial Catalog=HangfireStuff;Integrated Security=True;");
app.UseHangfireDashboard();
app.UseHangfireServer();_debug.log
_error.log
_info.log
has been created
Thanks for the repository, I was able to reproduce the issue. I removed the [assembly: log4net.Config.XmlConfigurator(Watch = true)] attribute and called XmlConfigurator.Configure(); before initialising Hangfire, and everything is working now. Here are the xmldocs for XmlConfiguratorAttribute class that explain everything:
Log4net will only look for assembly level configuration attributes once. When using the log4net assembly level attributes to control the configuration of log4net you must ensure that the first call to any of the log4net.Core.LoggerManager methods is made from the assembly with the configuration attributes.
If you cannot guarantee the order in which log4net calls will be made from different assemblies you must use programmatic configuration instead, i.e. call the XmlConfigurator.Configure() method directly.
It works me as well, thank you
I am happy to find a solution to my issue. I had started testing hangfire before timurabdurafeev posted his question. It looked really impressive however it caused log4net to stop working. I should have posted my question! Thanks for the question and answer.
Thanks for sharing the information. Worked well for me.
Most helpful comment
Thanks for the repository, I was able to reproduce the issue. I removed the
[assembly: log4net.Config.XmlConfigurator(Watch = true)]attribute and calledXmlConfigurator.Configure();before initialising Hangfire, and everything is working now. Here are the xmldocs forXmlConfiguratorAttributeclass that explain everything: