NLog not working with MSTest - any suggestions?

8 messages Options
Embed this post
Permalink
Peeks-2

NLog not working with MSTest - any suggestions?

Reply Threaded More More options
Print post
Permalink
Hi folks,
   I have been using NLog with my ASP.NET app perfectly.

   I now have some unit tests in my VS2008 solution and i've noticed that i'm not getting _any_ debugging info. If i run the website, it works fine.

I copied the nlog.config file the root directory of the mstest project. I've also made sure that it's 'copy always', so when the mstest is 'ran', the nlog.config is copied over to the test OUT directory, along side all the other .dll's that are automatically copied across .. so it's side-by-side.

i'm guessing NLog can't fine the config file because the NLogger instance exists, but it contains no data inside the instance .. so i doesn't think it needs to output to anywhere.

so .. i'm stuck :(

any suggestions? If someone has got it working with another unit testing program, then can they explain what they did for that, also?

cheers!
Peeks-2

Re: NLog not working with MSTest - any suggestions?

Reply Threaded More More options
Print post
Permalink
bump?
Jaroslaw Kowalski

Re: NLog not working with MSTest - any suggestions?

Reply Threaded More More options
Print post
Permalink
Can you try to use NLog.dll.nlog file instead? Make sure the file is in the same location where your NLog.dll ends up being copied.

Blake Pettersson

Re: NLog not working with MSTest - any suggestions?

Reply Threaded More More options
Print post
Permalink
I tried that and there is no difference. One thing that did work though was putting NLog.config into my %Program Files%\Microsoft Visual Studio 9.0\Common7\IDE folder. I believe this is because when you click "execute tests", MSTest.exe gets invoked. The question is how to get around this issue.
Blake Pettersson

Re: NLog not working with MSTest - any suggestions?

Reply Threaded More More options
Print post
Permalink
We can work around this by copying the Nlog.dll.nlog file whenever a text execution is running:  http://msdn.microsoft.com/en-us/library/ms182475(VS.80).aspx

Now the problem is reversed; it no longer works when running the application normally, but I assume this can be worked around by some MSBuild trickery.
Jaroslaw Kowalski

Re: NLog not working with MSTest - any suggestions?

Reply Threaded More More options
Print post
Permalink
Is it possible to configure your logging programmatically?

This can be as simple as:

LogManager.Configuration = new XmlLoggingConfiguration("c:\path\to\NLog.config")

Let me know if it works.
Blake Pettersson

Re: NLog not working with MSTest - any suggestions?

Reply Threaded More More options
Print post
Permalink
That did work actually, for running the app itself. The suggestion I posted higher up the thread stopped working for my unit tests once I started to use Testdriven.NET, but then it was just a matter of copying NLog.config in my unit test project.

  <Target Name="AfterBuild">
    <Copy SourceFiles="..\%ProjectName%\NLog.config" DestinationFolder=".\bin\Debug" />
  </Target>

With this I have logging for both my app and my unit test project, and there's no need to configure the logging programmatically :)

Jaroslaw Kowalski

Re: NLog not working with MSTest - any suggestions?

Reply Threaded More More options
Print post
Permalink
Perfect! Thanks for investigating!

On Tue, May 5, 2009 at 2:51 AM, Blake Pettersson (via Nabble) - No Reply <[hidden email]> wrote:
That did work actually, for running the app itself. The suggestion I posted higher up the thread stopped working for my unit tests once I started to use Testdriven.NET, but then it was just a matter of copying NLog.config in my unit test project.

  <Target Name="AfterBuild">
    <Copy SourceFiles="..\%ProjectName%\NLog.config" DestinationFolder=".\bin\Debug" />
  </Target>

With this I have logging for both my app and my unit test project, and there's no need to configure the logging programmatically :)