Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Including log4net Logging in Test output
pentop
#1 Posted : Wednesday, May 11, 2016 10:21:56 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/11/2016(UTC)
Posts: 7

Thanks: 2 times
Was thanked: 5 time(s) in 4 post(s)
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
#2 Posted : Wednesday, May 11, 2016 10:25:46 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
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.
1 user thanked Remco for this useful post.
pentop on 5/11/2016(UTC)
pentop
#3 Posted : Wednesday, May 11, 2016 10:52:46 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/11/2016(UTC)
Posts: 7

Thanks: 2 times
Was thanked: 5 time(s) in 4 post(s)
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!
2 users thanked pentop for this useful post.
Remco on 5/11/2016(UTC), tofutim on 7/8/2016(UTC)
tofutim
#4 Posted : Friday, July 8, 2016 1:23:35 AM(UTC)
Rank: Member

Groups: Registered
Joined: 8/27/2012(UTC)
Posts: 19
Location: California

Thanks: 2 times
Was thanked: 2 time(s) in 2 post(s)
I just want to also vote for log4net output in NCrunch.
tofutim
#5 Posted : Friday, July 8, 2016 1:40:57 AM(UTC)
Rank: Member

Groups: Registered
Joined: 8/27/2012(UTC)
Posts: 19
Location: California

Thanks: 2 times
Was thanked: 2 time(s) in 2 post(s)
@pentop I figured it out. Instead of using the usual xml configuration, take a look at this StackOverflow:

http://stackoverflow.com...-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.
1 user thanked tofutim for this useful post.
Remco on 7/8/2016(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.037 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download