# Enabling Logging with NLog

**URL:** <https://discuss.hangfire.io/t/enabling-logging-with-nlog/53>\
**Category:** question\
**Created:** [June 13, 2014, 2:22pm UTC](https://discuss.hangfire.io/t/enabling-logging-with-nlog/53 "2014-06-13T14:22:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tom](https://discuss.hangfire.io/u/tom)\
**Post date:** [June 13, 2014, 2:22pm UTC](https://discuss.hangfire.io/t/enabling-logging-with-nlog/53/1 "2014-06-13T14:22:32Z")

</div>

I’ve enabled logging in my project with NLog and it’s working fine, I can produce output from my application.

I’ve tested a job in hangfire which produced an exception like

```
"System.Reflection.TargetInvocationException
Exception has been thrown by the target of an invocation."

```

Nothing appeared in my logs for this. Should I expected to see a log entry from hangfire for such an exception?

I have nlog configured to capture all messages i.e.

```
  <rules>
    <logger name="*" minlevel="Debug" writeTo="file" />
  </rules>

```

I thought this would just work based on the documentation?

Thanks in advance,

Tom

---

<div class="post-metadata">

**Author:** ![odinserj](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/odinserj/32/648_2.png) [@odinserj](https://discuss.hangfire.io/u/odinserj)\
**Post date:** [June 18, 2014, 5:56pm UTC](https://discuss.hangfire.io/t/enabling-logging-with-nlog/53/2 "2014-06-18T17:56:24Z")

</div>

Oh, sorry for the absent answer! 😢 Yep, documentation should be correct, but looks like it doesn’t. I’ll try to look at this issue tonight.

---

<div class="post-metadata">

**Author:** ![tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tom](https://discuss.hangfire.io/u/tom)\
**Post date:** [June 18, 2014, 6:16pm UTC](https://discuss.hangfire.io/t/enabling-logging-with-nlog/53/3 "2014-06-18T18:16:32Z")

</div>

Thanks for following up, I look forward to your response!

---

<div class="post-metadata">

**Author:** ![odinserj](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/odinserj/32/648_2.png) [@odinserj](https://discuss.hangfire.io/u/odinserj)\
**Post date:** [June 19, 2014, 6:48pm UTC](https://discuss.hangfire.io/t/enabling-logging-with-nlog/53/4 "2014-06-19T18:48:50Z")

</div>

Please tell me exact versions of the following packages you use and the full stack trace of your exception.

- `NLog`
- `Common.Logging`
- `Common.Logging.NLog`

I’ve tried to install NLog support for the project using steps written in [the documentation](http://docs.hangfire.io/en/latest/users-guide/deployment-to-production/adding-logging.html) (but changed the `Common.Logging.NLog20` with `Common.Logging.NLog`) with the following versions, and all is working fine for me.

- `NLog 3.0.0.0`
- `Common.Logging 2.1.2`
- `Common.Logging.NLog 2.0.0`

---

<div class="post-metadata">

**Author:** ![tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tom](https://discuss.hangfire.io/u/tom)\
**Post date:** [June 24, 2014, 4:37pm UTC](https://discuss.hangfire.io/t/enabling-logging-with-nlog/53/5 "2014-06-24T16:37:43Z")

</div>

So, I was having a really hard time getting this working.  
I couldn’t get the configuration of the logging adapter to work as per the [documentation](http://docs.hangfire.io/en/latest/users-guide/deployment-to-production/adding-logging.html), I kept getting errors when trying to declare the LogManager.Adapter.

I ended up moving my config into the web.config file and still had problems getting the project to run.

In the end, the problem was the installation of the nuget package.  
I uninstalled **Common.Logging.NLog** and installed **Common.Logging.NLog20**

This seems to be a known dependency issue, people can read more about it here;

- [https://github.com/net-commons/common-logging/issues/23](https://github.com/net-commons/common-logging/issues/23)
- [http://stackoverflow.com/questions/22223486/support-for-nlog-2-1](http://stackoverflow.com/questions/22223486/support-for-nlog-2-1)

You should probably change the documentation reference for the Install-Package command.

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![odinserj](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/odinserj/32/648_2.png) [@odinserj](https://discuss.hangfire.io/u/odinserj)\
**Post date:** [June 26, 2014, 7:56am UTC](https://discuss.hangfire.io/t/enabling-logging-with-nlog/53/6 "2014-06-26T07:56:15Z")

</div>

Unfortunately `Common.Logging.NLog20` does not work with `Common.Logging 2.2.0` (the latest stable version), because version 2.2.0 contains breaking changes ☹. You have problems with `Common.Logging.NLog` package, I had problems with `Common.Logging.NLog20` package.

In Hangfire I tried to claim the lowest possible dependency version (Common.Logging 2.1.2, Newtonsoft.Json 5.0.1, etc.) for easier integration into existing projects without updating dependencies (that can cause breaking changes). But tried to choose only references to those versions that allows Hangfire to work after an upgrade to the latest stable.

Currently both `2.1.2` (referenced) and `2.2.0` (latest) versions of the `Common.Logging` package contain different problems regarding to a version. To prevent the configuration burden, I’ll update Hangfire to claim the latest, `2.2.0` version of `Common.Logging`, so everyone will have the same problems :).

---

<div class="post-metadata">

**Author:** ![tom](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@tom](https://discuss.hangfire.io/u/tom)\
**Post date:** [June 26, 2014, 12:38pm UTC](https://discuss.hangfire.io/t/enabling-logging-with-nlog/53/7 "2014-06-26T12:38:00Z")

</div>

Interesting. I’m using

- Hangfire 0.9.1
- Common.Logging 2.2.0
- Common.Logging.NLog20 2.2.0

Everything is working fine for me! I won’t do anything to disturb this for now 🙂

---

<div class="post-metadata">

**Author:** ![odinserj](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/odinserj/32/648_2.png) [@odinserj](https://discuss.hangfire.io/u/odinserj)\
**Post date:** [June 26, 2014, 12:45pm UTC](https://discuss.hangfire.io/t/enabling-logging-with-nlog/53/8 "2014-06-26T12:45:15Z")

</div>

And I’ll check the `Common.Logging 2.1.2` with `Common.Logging.NLog20` once again. If it does not work, then I update the reference to `Common.Logging 2.2.0` package.
