Hi
I create a Test Project in VSTS. This kind of project is a special type of project test methods in which can be recognized by Test Manager window or Test View window.
I modify the code in the project with some logging code with log4net.
Then run it from Visual Studio Command Prompt with MSTest, or from Test Manager window.
But no log file created with logging message.
Does log4net support Test Project in VSTS? I looked into the source code of log4net and found there is a "GetExecuteAssembly()". The return value of this in my Test project is null.
Perhaps this is because Test project does not have an AssemblyInfo.cs when created. So even if I add an AssemblyInfo.cs with log4net info, the log still not generated.
Do you know why and the solution?
My configuration is as follows which acts well in another Console App.:
1 AssemblyInfo.cs:[assembly: log4net.Config.XmlConfigurator(Watch = true)]
2 App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
</configSections>
<appSettings>
<!-- <add key="log4net.Internal.Debug" value="true"/> -->
</appSettings>
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<file value="logs\DALTest-log-file.txt" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger -- %message%newline" />
</layout>
</appender>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger -- %message%newline" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="ConsoleAppender" />
</root>
</log4net>
</configuration>
3 Code in class:
using log4net;
...
private static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
...
logger.Debug("Test get-customer-list begins!");
...