Hi all,
I've switched to a new machine and have somehow lost the ability to see my log4net logs in the test window output.
My log4net config is using a ConsoleAppender and a RollingFileAppender, I know that log4net is set up fine as I can see the RollingFileAppender output on disk, but I want the results in the test output window too!
Anyone know how to get this back?
Remco NCrunch Developer
#8725
11 May 2016 10:25 UTC
Hi, thanks for sharing this issue.
NCrunch itself has no knowledge of Log4net or any of its configuration - as far as the test runner is concerned, it's just code to be run.
From what I remember about log4net, it has a rather involved configuration system. Is it possible that the log4net config file hasn't been included in the project you're working on? Are you experiencing this issue also with other test runners? NCrunch collects its trace output from process trace/debug stream and the console output stream.
NCrunch itself has no knowledge of Log4net or any of its configuration - as far as the test runner is concerned, it's just code to be run.
From what I remember about log4net, it has a rather involved configuration system. Is it possible that the log4net config file hasn't been included in the project you're working on? Are you experiencing this issue also with other test runners? NCrunch collects its trace output from process trace/debug stream and the console output stream.
Thanks Remco! You were right, nothing to do with NCrunch - but you pointed me in the right direction. If log4net can get messages onto the console or trace/debug stream, they turn up in the test output window as you say.
Thanks v much for the prompt help!
Thanks v much for the prompt help!
I just want to also vote for log4net output in NCrunch.
@pentop I figured it out. Instead of using the usual xml configuration, take a look at this StackOverflow:
http://stackoverflow.com/questions/16336917/can-you-configure-log4net-in-code-instead-of-using-a-config-file
This will allow you to setup log4net in code instead of the app.config. In my case:
public class Logger
{
public static void Setup()
{
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
PatternLayout patternLayout = new PatternLayout();
patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
patternLayout.ActivateOptions();
var consoleAppender = new ConsoleAppender();
consoleAppender.Layout = patternLayout;
consoleAppender.ActivateOptions();
hierarchy.Root.AddAppender(consoleAppender);
hierarchy.Root.Level = Level.All;
hierarchy.Configured = true;
}
}
then before your tests, run Logger.Setup(). This will allow the log4net output to show up in the Console.
http://stackoverflow.com/questions/16336917/can-you-configure-log4net-in-code-instead-of-using-a-config-file
This will allow you to setup log4net in code instead of the app.config. In my case:
public class Logger
{
public static void Setup()
{
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
PatternLayout patternLayout = new PatternLayout();
patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
patternLayout.ActivateOptions();
var consoleAppender = new ConsoleAppender();
consoleAppender.Layout = patternLayout;
consoleAppender.ActivateOptions();
hierarchy.Root.AddAppender(consoleAppender);
hierarchy.Root.Level = Level.All;
hierarchy.Configured = true;
}
}
then before your tests, run Logger.Setup(). This will allow the log4net output to show up in the Console.
Post a reply
Log in to reply.