ハードウェア デバイス上のベンダーの Rest Api に接続する REST エンドポイントの統合テストに取り組んでいます。私のソフトウェアは、定期的に物理デバイスでテストする必要があります。テスト プロジェクト (VSTest VS 2015) を作成し、テスト ハーネスにログを追加したいと考えています。log4net には膨大な量のドキュメントがあることを認識していますが、まだ機能させることができません。私の目標は、コンソールとファイルにログを記録することです。ベンダーは、私のテストが完了したことを検証するためにログ ファイルを必要としています。
まず、log4net を初期化してスタンドアロン ファイルを読み取ります。
using log4net.Config;
using log4net;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics;
namespace MyProgram
{
[TestClass]
public class AssemblyInitializer
{
private static ILog log = null;
[AssemblyInitialize]
public static void Configure(TestContext Context)
{
Debug.WriteLine("Starting log4net setup and configuration");
XmlConfigurator.Configure(new FileInfo("log4net.properties"));
log = LogManager.GetLogger(typeof(AssemblyInitializer));
log.Debug("log4net initialized for Integration Test");
Debug.WriteLine("Completed log4net setup and configuration");
}
}
}
私の log4net.properties ファイル:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionpattern value="%date [%thread] %-5level %logger{1} - %message%newline"/>
</layout>
</appender>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="IntegrationTests.log" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG">
<appender-ref ref="ConsoleAppender"/>
<appender-ref ref="FileAppender"/>
</level>
</root>
</log4net>
</configuration>
テスト エクスプローラーが Assembly.Info ファイルを読み取るとは思えませんが、念のため参照を含めました。
[assembly: log4net.Config.XmlConfigurator(Watch = false)]
考えられることはほぼすべて試しました。私はアイデアがありません。どんな助けでも大歓迎です。