title: .NET/C# Trace - view trace log in dialog & optionally save to file
body: <p>I want to implement some basic tracing in a simple c# (WPF) application that will only be used internally by testers. I basically want the testers to be able to view a log of what they've done and then <em>optionally</em> save it to a file (of their choosing). This would allow the testers to see what they've done thus far in the test and optionally save the log to file for posterity or whatever.</p>
  
  <p>In researching how to implement simple tracing in .Net (using <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.trace.aspx" rel="nofollow noreferrer">System.Diagnostics.Trace</a>), it seems the default answer is to use <a href="http://logging.apache.org/log4net/" rel="nofollow noreferrer">log4net</a> (or perhaps <a href="http://nlog-project.org/" rel="nofollow noreferrer">NLog</a>, as referenced in <a href="https://stackoverflow.com/questions/1663891/is-log4net-dead/7060997#7060997">Is log4net dead?</a>) instead. My issue with that is that my tracing doesn't need to be fully-featured or anything special, so it seems like overkill to implement an external library (which seems to be backed up by Jeff Atwood himself in a comment in <a href="https://stackoverflow.com/questions/61110/how-to-save-the-output-of-a-console-application/61134#61134">How to save the output of a console application</a> (and others elsewhere, but still...)). If either log4net or NLog is, in fact, the best/only answer (even in my case), I may still accept it (i.e. I'm not entirely closed to the idea of using them, but not terribly excited in it), but try not to harp on (/focus solely on) that one (if possible)...</p>
  
  <p>With that in mind, does anyone have any suggestions on how to implement the listeners such that I can pop open a dialog with the trace log visible (e.g. via a <code>View Log</code> button) and then optionally save the contents of that dialog (or the trace log itself) to a file (e.g. via a <code>Save Log</code> button in the `View )?</p>
  
  <p>It seems like it would be relatively simple to implement a listener that simply logs the traces to a collection of some sort in the app, in which case <code>View</code> simply shows the collection in a listbox or something and <code>Save</code> just saves that list to file (duh), but then what if the app stays open for a long time and the trace log grows super-large? Perhaps a buffer-type collection that only logs the last <code>x</code> messages? Suggestions?</p>