Friday, May 18, 2012
 
The best way to analyze your logs! Minimize
 Log4Net Mail archive   

The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.

Subject: Log4Net and MSTest
Prev Next
You are not authorized to post a reply.

Author Messages
Pelton, Brian

10/10/2008 6:05 PM  

Does anyone use MSTest and if so, have you had success in getting logging to work with your tests?

 

Normally, in my application log4net is configured by a call to:

   log4net.Config.XmlConfigurator.Configure(logConfigFile);

 

But, I’m writing tests for one of my library projects, so I don’t see a good place to put such a statement.

 

I thought I would try using the assembly attribute and an app.config file to configure log4net, but this doesn’t seem to work.

 

In a file called “Logging.cs” I have this;

 

using log4net.Config;

[assembly: XmlConfigurator()]

 

 

And my app.config looks like this:

 

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

  <configSections>

    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >

      <section name="SNIP.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />

    </sectionGroup>

    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />

  </configSections>

  <userSettings>

    <SNIP.Properties.Settings>

      <setting name="DefaultEnvironmentPath" serializeAs="String">

        <valueSNIP\env\unittest</value>

      </setting>

      <setting name="ConfigurationFilename" serializeAs="String">

        <value>SNIP.config.xml</value>

      </setting>

      <setting name="Log4NetConfigurationFilename" serializeAs="String">

        <value>log4net.config.xml</value>

      </setting>

    </SNIP.Properties.Settings>

  </userSettings>

  <log4net>

    <appender name="DetailedAppender" type="log4net.Appender.FileAppender, log4net">

      <file type="log4net.Util.PatternString" value="log4net.log" />

      <appendToFile value="false" />

      <layout type="log4net.Layout.PatternLayout">

        <conversionPattern value="%date %-5level %logger - %message%newline" />

      </layout>

    </appender>

    <root>

      <level value="INFO" />

      <appender-ref ref="DetailedAppender" />

    </root>

    <logger name="NHibernate">

      <level value="WARN" />

    </logger>

  </log4net>

</configuration>

 

 

 

Brian Pelton

J.G. Boswell Company

bpelton@jgboswell.com

 

Pelton, Brian

10/10/2008 6:16 PM  

Actually it is working!  But the file isn’t where I thought it would be (in the TestResults\out folder)

 

It was actually written to:

 

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\log4net.log

 

 

So the working directory is not the “out” directory as I had assumed.  Okay, well at least it is working!

 

--Brian

 

You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > Log4Net and MSTest



ActiveForums 3.7

 

 

 

 

 

 

 

 

Log4Net Dashboard

Log analysis and monitoring made easy!

Log4Net Dashboard is a log viewer that can read log statements from a variety of logging output targets.

You can download a free developer version.

  

Check it out!

On the demonstration site you can try it  with live data.demo.l4ndash.com - Try Log4Net Dashboard with live data

The mail archive is a copy of all the mail sent to the mail address: log4net-user@logging.apache.org, organized as a forum.

If you would like to participate in the mail list, send a mail to log4net-user-subscribe@logging.apache.org.

More information about the mailing list is available on: http://logging.apache.org/log4net/support.html

 

A complete topic list is available and can be viewed here (warning, it takes some time to load)

 

Copyright 2005-2008 by FaktNet AS Terms Of Use Privacy Statement