# Log4net, howto?

**URL:** https://discuss.hangfire.io/t/log4net-howto/3314
**Category:** question
**Tags:** log4net
**Created:** [May 15, 2017, 12:40pm UTC](https://discuss.hangfire.io/t/log4net-howto/3314 "2017-05-15T12:40:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![MrFooBar](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/mrfoobar/32/986_2.png) [@MrFooBar](https://discuss.hangfire.io/u/MrFooBar)
#### Post date: [May 15, 2017, 12:40pm UTC](https://discuss.hangfire.io/t/log4net-howto/3314/1 "2017-05-15T12:40:04Z")

</div>

Hello.  
I have installed log4net and configured 1 appender named “ConsoleAppender”.  
Now when i try to start my application, all I get is this:

> ```
> Exception occured resolving a log provider. Logging for this assembly Hangfire.Core, Version=1.6.12.0, Culture=neutral, PublicKeyToken=null is disabled. System.ArgumentNullException: Value cannot be null.
> Parameter name: method
> at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, Expression arg0)
> at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable`1 arguments)
> at Hangfire.Logging.LogProviders.Log4NetLogProvider.GetGetLoggerMethodCall()
> at Hangfire.Logging.LogProviders.Log4NetLogProvider..ctor()
> at Hangfire.Logging.LogProvider.<>c.<.cctor>b__10_2()
> at Hangfire.Logging.LogProvider.ResolveLogProvider()
> 
> ```

According to this url, everything should just work?  
[http://docs.hangfire.io/en/latest/configuration/configuring-logging.html](http://docs.hangfire.io/en/latest/configuration/configuring-logging.html)

Do I need to add some sort of LOG4NET config to my XML in order to get this to work?

---

<div class="post-metadata">

### Author: ![h4ckm03d](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/h4ckm03d/32/950_2.png) [@h4ckm03d](https://discuss.hangfire.io/u/h4ckm03d)
#### Post date: [August 16, 2017, 5:05am UTC](https://discuss.hangfire.io/t/log4net-howto/3314/2 "2017-08-16T05:05:47Z")

</div>

```
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
  <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender" >
<file value="App_Data/Logs/Logs.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
  <conversionPattern value="%-5level %date [%-5.5thread] %-40.40logger - %message%newline" />
</layout>
  </appender>
  <root>
<appender-ref ref="RollingFileAppender" />
<level value="ALL" />
  </root>
</log4net>

```

I have same problem using those config. Log4net works on application but got error on hangfire.  
My application run on .net core 1.1. I have no idea how to get rid the problem.

---

<div class="post-metadata">

### Author: ![jisleyjr](https://avatars.discourse-cdn.com/v4/letter/j/c89c15/32.png) [@jisleyjr](https://discuss.hangfire.io/u/jisleyjr)
#### Post date: [September 6, 2017, 5:27pm UTC](https://discuss.hangfire.io/t/log4net-howto/3314/3 "2017-09-06T17:27:04Z")

</div>

Hello, did you ever figure out the issue you were having? I am using .net core also.

Edit: Did some more digging and found this issue for liblog: [https://github.com/damianh/LibLog/issues/126](https://github.com/damianh/LibLog/issues/126)

Might need to switch to a different logger.

---

<div class="post-metadata">

### Author: ![MrFooBar](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/mrfoobar/32/986_2.png) [@MrFooBar](https://discuss.hangfire.io/u/MrFooBar)
#### Post date: [September 7, 2017, 6:38am UTC](https://discuss.hangfire.io/t/log4net-howto/3314/4 "2017-09-07T06:38:21Z")

</div>

I had to do a workaround, I used this method to manually add a logger:  
LogProvider.SetCurrentLogProvider(new HangfireLoggerProvider());

And since I nwver understood what class to use, I had to implement my own:

```
    public class HangfireLoggerProvider : ILogProvider
    {
        public ILog GetLogger(string name)
        {
            return new HangefireLogger(name);
        }

        public class HangefireLogger : ILog
        {
            private readonly log4net.ILog _log4Netlogger;

            public HangefireLogger(string name)
            {
                _log4Netlogger = log4net.LogManager.GetLogger("Hangfire", name);
            }

            public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception)
            {
             ....
           }
}
```
