Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6360193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:37:03+00:00 2026-05-24T23:37:03+00:00

I just started testing xUnit.net, but it doesn’t seem to capture any output (Console,

  • 0

I just started testing xUnit.net, but it doesn’t seem to capture any output (Console, Debug, Trace), as I would have expected.

Is that possible? I am using a sample .NET 4.0 class-library with xUnit.net 1.8.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:37:04+00:00Added an answer on May 24, 2026 at 11:37 pm

    In general, it’s a bad road to go down to be reliant on logging and tests. The pass/fail should be the outcome of the tests. And they simply shouldn’t get to the stage where there’s enough stuff going on that looking at a trace will be necessary.

    The xunit.gui.exe shows Console and Trace output, xunit.console.exe does not. If it’s important, you could hook up a TraceListener which redirects to a file by making appropriate standard .NET config entries (Theres’ a FileWriterTraceListener which you should be able to hook in if you google it).


    UPDATE: As discussed in his blog post, Damian Hickey has a good example of a possible substitute – wiring logging to the xUnit 2 ITestOutputHelper as demonstrated in https://github.com/damianh/CapturingLogOutputWithXunit2AndParallelTests/blob/master/src/Lib.Tests/Tests.cs

    UPDATE 2: In some cases, one can add logging and feed it to the ITestOutputHelper without involving LogContext by using a simple adapter as follows (I only have it in F#, sorry):

    // Requirement: Make SUT depend on Serilog NuGet
    // Requirement: Make Tests depend on Serilog.Sinks.Observable
    
    type TestOutputAdapter(testOutput : Xunit.Abstractions.ITestOutputHelper) =
        let formatter = Serilog.Formatting.Display.MessageTemplateTextFormatter(
            "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}", null);
        let write logEvent =
            use writer = new System.IO.StringWriter()
            formatter.Format(logEvent, writer);
            writer |> string |> testOutput.WriteLine
        member __.Subscribe(source: IObservable<Serilog.Events.LogEvent>) =
            source.Subscribe write
    
    let createLogger hookObservers =
        LoggerConfiguration()
            .WriteTo.Observers(Action<_> hookObservers)
            .CreateLogger()
    let createTestOutputLogger (output: ITestOutputHelper) =
        let adapter = TestOutputAdapter testOutputHelper
        createLogger (adapter.Subscribe >> ignore)
    
    type Tests(testOutputHelper) =
        let log = createTestOutputLogger testOutputHelper
    
        [<Fact>] let feedToSut () =
            // TODO pass log to System Under Test either as a ctor arg or a method arg
    

    The difference with this approach vs using the log context is that logging to the global [contextualized] Serilog Logger will not get picked up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started out with testing some php mvc framework In it, it
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I've just started doing some real-world performance testing on my Fluent NHibernate / SQLite
I've just started doing some PowerShell scripting, and I'm running into a problem testing
I have been looking at using TDD and implementing proper testing (only just started
I'm just getting started with learning about Unit testing (and TDD in general). My
Just started getting a bunch of errors on our C# .Net app that seemed
Just started to get my feet wet with C# and .NET, liking it so
Just started my first MVC 2.0 .net application. And I set up some default
I just started a new project, and now with ASP.NET MVC being designed in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.