2016-09-08 19 views
0

私はlog4netを使っていくつかのログを書きたいテストアセンブリ(MyTestProject)を持っています。 here示唆したようにこのように私は私がログを設定アセンブリと同じ名前の設定ファイルを作成しました。しかしNUnitでテストするときにログファイルを書き込む

[TestFixture] 
public class MyTest 
{ 

    private readonly ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 

    [TestFixtureSetUp] 
    public void Init() 
    { 
     log.Info("Something to log"); 
     ... 
    } 
} 

:私のコード内

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

<!-- .NET application configuration file 
This file must have the exact same name as your application with 
.config appended to it. For example if your application is testApp.exe 
then the config file must be testApp.exe.config it must also be in the 
same directory as the application. --> 
<configuration> 
    <configSections> 
    <!-- Register the section handler for the log4net section --> 
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /> 
    <sectionGroup name="NUnit"> 
     <!-- For .NET 2.0 Beta 2 replace the lines with the following --> 
     <section name="TestCaseBuilder" type="System.Configuration.NameValueSectionHandler, System, Version=2.0.50215.44, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     <section name="TestRunner" type="System.Configuration.NameValueSectionHandler, System, Version=2.0.50215.44, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
    </sectionGroup> 
    </configSections> 
    <NUnit> 
     <TestCaseBuilder> 
     <add key="OldStyleTestCases" value="false" /> 
     </TestCaseBuilder> 
     <TestRunner> 
     <!-- Valid values are STA,MTA. Others ignored. --> 
     <add key="ApartmentState" value="STA" /> 
     <!-- See ThreadPriority enum for other valid values --> 
     <add key="ThreadPriority" value="Normal" /> 
     </TestRunner> 
    </NUnit> 
    <appSettings> 
     <add key="ApartmentState" value="STA" /> 
     <add key="apartment" value="STA" /> 
    </appSettings> 

    <!-- This section contains the log4net configuration settings --> 
    <log4net debug="true"> 

     <!-- Define some output appenders --> 

     <appender name="LogFileAppender" type="log4net.Appender.FileAppender,log4net" > 
     <param name="File" value="D:/data.log" /> 
     <param name="AppendToFile" value="false" /> 
     <layout type="log4net.Layout.PatternLayout,log4net"> 
      <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" /> 
     </layout> 
     </appender> 


     <!-- Setup the root category, add the appenders and set the default priority --> 
     <root> 
     <level value="DEBUG" /> 
     <appender-ref ref="LogFileAppender" /> 
     </root> 
    </log4net> 
</configuration> 

を次のように私は、ログを設定しましたテストを実行するとそのようなファイルはありませんD:/data.logが作成されます。コードをデバッグしてアペンダーに時計を追加するとさらに疑わしいのですが、logから空のコレクションがあります。

答えて

0

私は何時間も私を抱きしめています。

ファイルが保存されるディレクトリを調べましたが、そこにはタイムスタンプが最近のものではないため、以前のテストランのものがありました。ファイルを削除しようとすると、現在使用中であるというメッセージがnunit-agent-x86.exeから届きました。だから私はTaskManagerのプロセスを抹殺し、テストを再実行します。今はすべて正常に動作し、ファイルにログインします。

関連する問題