Can't load NLog.config of my Class library project from an ASP web project

1,275 views
Skip to first unread message

Víctor Portela Romero

unread,
Nov 20, 2012, 12:38:01 PM11/20/12
to nlog-...@googlegroups.com

Hi!

I have a problem reading the configuration file (NLog.config) from my class library project when I call it from my ASP.NET MVC4 project.

I tested my code using an Unit Test Project and reads the configuration file properly and makes logging correctly on the file that I specified on the NLog.config, so the NLog.config is correctly defined.

I also set "Copy always" at Copy to Output Directory settings, just like the tutorial says.

The problem is that when I called the class library project, from my ASP project, I realized that wasn't making any kind of log, and when I debugged, I saw that It wasn't picking the configuration from NLog.config, and for that reason, my project didn't know when and where to log.

I when look into "ASP project folder"/bin, there are the files from NLog: NLog.dll, NLog.config and NLog.xml, so in theory, the ASP project, can access without problem to the NLog files.

I read the tutorial from NLog but I can't figured out the solution. Just can´t understand why from my test project works properly but when I make the same call from my ASP project just don't work.

This is my configuration file for NLog.

<?xml version="1.0" encoding="utf-8" ?>
<nlog throwExceptions="true" 
  xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<targets>
  <target name="logfile" xsi:type="File" fileName="C:\logfile.txt" layout="${callsite:fileName=true} - ${longdate} - ${level:uppercase=true} - ${logger} - ${message}"/>
</targets>

<rules>
  <logger name="*" minlevel="Info" writeTo="logfile" />
</rules>
</nlog>

And within my classes, I create the logger this way:

private static Logger logger = LogManager.GetCurrentClassLogger();

Can anybody help me with this problem?


I make the same question here if anyone want to answer there too ;)

http://stackoverflow.com/questions/13469474/reading-nlog-config-from-nlog-in-api-rest-net

Greetigs!

Víctor Portela Romero

unread,
Nov 21, 2012, 4:58:06 PM11/21/12
to nlog-...@googlegroups.com
I figured out a solution, It seems that if I manually copy the NLog.config file manually inside the solution explorer from one project to another, it works. I don´t know if is the best solution, but It worked for me.

Jason LaFlair

unread,
Nov 21, 2012, 5:22:19 PM11/21/12
to nlog-...@googlegroups.com
In our solution - we keep the NLog config in a common location, then add it to the 'entry point' projects as a linked reference.  Then you just need to update the one main file.

Also, you should only need the files at the entry points (console app, website, etc) - shouldn't be needed in a library project.

Jason.

--
You received this message because you are subscribed to the Google Groups "NLog-Users" group.
To post to this group, send email to nlog-...@googlegroups.com.
To unsubscribe from this group, send email to nlog-users+...@googlegroups.com.
Visit this group at http://groups.google.com/group/nlog-users?hl=en.
 
 

Víctor Portela Romero

unread,
Nov 21, 2012, 6:01:53 PM11/21/12
to nlog-...@googlegroups.com
Thanks for de advice, I'll do that ;)
Reply all
Reply to author
Forward
0 new messages