vijay sahu
vijay sahu

Reputation: 823

Project Reference which has Multiple DLL itself

I have one query...

I have one class library project which has Exception logging mechanism. For logging exception in db and file I am using NLog.

I wanted to implement this Exception Class library project in such a way so that I can use it's DLL file to any project in future.

The problem is that when I am referring this DLL to other project it is seeking for NLog dll too. Hence getting error like

[Could not load file or assembly 'NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c' or one of its dependencies. The system cannot find the file specified.']

But when I am adding the dll to my current calling project then everything start working means it's clear that it seeking for NLOG DLL too.

But it will be completely pathetic if I am going to add both DLL(Nlog , ClassLibrary DLL to calling project).

Please suggest your opinion on this.

Please find the attached screen shot of my solution.

enter image description here

And the exception is like this :

enter image description here

Upvotes: 0

Views: 223

Answers (1)

Julian
Julian

Reputation: 36830

Only for the class library you need to reference NLog, when the only log messages are written by that project.

I've made an example that show it works:

https://github.com/304NotModified/NLog-Demo-cases/tree/master/ConsoleWithClassLib

edit:

added a 2nd demo, in this case NLog is configured by the class library. In this case it's important to configure NLog before logging ;)

relevant part in the library:

// setup config
var configuration = new LoggingConfiguration();
configuration.AddRuleForAllLevels(new ConsoleTarget());
LogManager.Configuration = configuration;

// log
Logger logger = LogManager.GetCurrentClassLogger();
logger.Info("Init class1");

Full demo: https://github.com/304NotModified/NLog-Demo-cases/tree/master/ConsoleWithClassLib2

Upvotes: 1

Related Questions