Turn Off Logging?

logging
Tags: #<Tag:0x00007f6a02a71b60>

#1

Is there a way to turn off logging that Hangfire does? We are using our own abstraction on top of log4Net and I don’t want all this extra noise coming from the Hangfire logger.


#2

There is already a NoOpLogger which requires null to be passed in as the log provider:
http://docs.hangfire.io/en/latest/configuration/configuring-logging.html


I.e:

LogProvider.SetCurrentLogProvider(null);

Please note that you cannot use Hangfire’s configuration extension to do this as it does not allow a null provider:


#3

I think we should allow to pass a null identifier, or (may be this is better?) add a new method UseNoOpLogger or somethink like that. On the other hand, modern logging libraries allow to disable loggers by wildcard Hangfire.*, however it may be difficult to learn how to do that. Guys, what do you think?


#4

I think that we should do both, allow null in UseLogProvider as this is a valid input and also add UseNoOpLogger as this matches the rest of the helpers within GlobalConfigurationExtensions. The fluent interface that GlobalConfigurationExtensions provides is quite nice and a UseNoOpLogger method would compliment that.

I wouldn’t rely on a logging provider’s ability to filter as the user may have a non-standard setup.


#5

However, without logging it will be pretty hard to see what’s wrong with background processing. It is like catching all the exceptions for web request. Nice – no exceptions, no problems. Maybe it is much better to lower the extra noise instead?

@CheesePizza, what logging messages annoyed you?


#6

Well ideally I wouldn’t want any logging messages to come from Hangfire. Admittedly, our logging solution is a bit overkill. By requirement, we have to interact with a company wide enterprise logger which is a WCF service. But we are working in a Web API solution where we want our own logging. So we are using bits of this enterprise logger to satisfy requirements. Then we have our logging inside our application which is common logging and log4net, and inside our Web API, we are not logging everything.

So even if we change our log4net configuration to say, INFO for example, we would get INFO messages from Hangfire. We are not interested in INFO messages from Hangfire, only things we are explicitly coding for within the application.

Giving users the option to opt in to logging seems like a good approach for those that already having a logging implementation with their application.


#7

Even FATAL exception messages that tell you background processing is not working at all? How do you debug your application when abnormal things happen?


#8

I am interested on how I can bring the noise level down.

How can I only allow FATAL logging to come from hangfire?

I think by default the logging should be FATAL or WARN?


#9

@haroon, most of the popular logging frameworks allow to configure the minimum log level to log. What framework do you use? Another option – to tune the messages themselves in Hangfire itself. What noise messages do you have?


#10

@odinserj I currently have nlog set up as:

  <logger name="Hangfire.*" minlevel="Fatal" writeTo="logfile"  />
  <logger name="Awesome.*" minLevel="Trace" appendTo="syslog" enabled="false" />
  <logger name="Awesome.*" minLevel="Trace" appendTo="logfile" />

With this configuration I am still getting Debug and Trace logs in my syslog (papertrail app).

What am I doing wrong? I only want the Fatal errors to appear in my log files.


#11

@haroon, what version of Hangfire are you using? There is a bug with logger names in 1.5.0 betas, that causes loggers to use ToString method instead of GetType, and, for example, workers have Worker #XXXXX name instead of Hangfire.Server.Worker.


#12

Hi @odinserj,

I am having the same problem. I would like to separate out the Hangfire logging from my regular application logging. I am using Hangfire v1.5.3 and NLog v4.2.3. I have similar logging filters set up as @haroon, but I am still getting logging going on to my sources anyway. The “logger” shows up as “Hangfire.Server.RecurringJobScheduler” or something similar so I would hope that this specifying “Hangfire.*” is not the issue, but something else where Hangfire is bypassing the NLog settings. Please help. Thank you.


#13

Hi again. This may have resolved itself – I didn’t realize that I had to restart the server for the logging to change, but I think now that I have made changes to the nlog.config file and restarted the server, my changes have stuck.


#14

this is really annoying…I have the same problem as the OP and I am unable to get logging working as the Hangfire project references other project that use our logger and I think that HF think that it should then use Log4net…

It does not throw an exception but it does not seem to log either. I’ve tried setting the currentprovider to null and use only our log4net abstractnio but it does not log it anywhere I can see