2

What would be an example of a default logger in NUnit to log the information?

Some documentation says Log4net is not supported now.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
kumar
  • 191
  • 1
  • 2
  • 5
  • 2
    Which documents saying that log4net is not supported, could you give an url? – sll Aug 10 '11 at 09:20
  • Not about Log4net and logging, but related (general debugging in NUnit unit tests): *[How do I get nunit3-console to output my debug to screen?](https://stackoverflow.com/questions/46405753/how-do-i-get-nunit3-console-to-output-my-debug-to-screen-on-a-windows-box)* - *"in NUnit 3, you should use TestContext.WriteLine(...) in your tests"*. It [works on Linux](https://stackoverflow.com/questions/46405753/how-do-i-get-nunit3-console-to-output-my-debug-to-screen-on-a-windows-box#comment110657051_46407376) as well. – Peter Mortensen Jul 10 '23 at 18:58

2 Answers2

1

You can use the normal .NET Trace or Debug classes to log messages that NUnit will later display.

Jordão
  • 55,340
  • 13
  • 112
  • 144
  • Yep but this kind of logs only can be observed whils test run but what if requirement is to save logs from each tests run – sll Aug 10 '11 at 09:21
  • You could do this with custom `TraceListener`s. – Jordão Aug 10 '11 at 11:56
  • 1
    No, it's a .NET [feature](http://msdn.microsoft.com/en-us/library/system.diagnostics.tracelistener.aspx). There's even a [`TextWriterTraceListener`](http://msdn.microsoft.com/en-us/library/system.diagnostics.textwritertracelistener.aspx) that you can use to write to a file. – Jordão Aug 10 '11 at 12:11
  • but this would be a custom implementation and you can;'t write all NUNit diagnostic messages in this way – sll Aug 10 '11 at 12:57
  • Ah, so it's NUnit messages that you want to write, not your own messages? – Jordão Aug 10 '11 at 14:13
  • 1
    I believe Kumar is asking about NUnit logger – sll Aug 10 '11 at 14:48
0

You can add Common.Logging reference (with Log4net) and add ConsoleAppender in your configuration file. After configuring the appender, you will see logging information when running your unit tests.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131