0

In my C# program I intend to catch every potential log like this:

public static void Main(string[] args)
{
   using (new ConsoleToFile("./output.log"))
   {
      doMain(args, parser, options, directConsole);
   }
}

ConsoleToFile is this classic one:

public class ConsoleToFile : IDisposable
{
    private readonly StreamWriter fileOutput;
    private readonly TextWriter oldOutput;

    /// <summary>
    /// Create a new object to redirect the output
    /// </summary>
    /// <param name="outFileName">
    /// The name of the file to capture console output
    /// </param>
    public ConsoleToFile(string outFileName)
    {
        oldOutput = Console.Out;
        fileOutput = new StreamWriter(
            new FileStream(outFileName, FileMode.Create)
            );
        fileOutput.AutoFlush = true;
        Console.SetOut(fileOutput);
        Console.SetError(fileOutput);
    }

    // Dispose() is called automatically when the object
    // goes out of scope

    #region IDisposable Members

    public void Dispose()
    {
        Console.SetOut(oldOutput); // Restore the console output
        fileOutput.Close(); // Done with the file
    }

    #endregion
}

Concerning output generated in my code this works well!

But I also have included the fop.dll from apache.fop (I generated it with IKVM).

The Problem: This fop-DLL logs out to console as if the redirecting wouldn't be present.

e.g. classic nasty warnings like:

"WARNING: padding-* properties are not applicable to fo:table-header, but a non-zero value for padding was found."

Any idea how to redirect also these logging to my file "output.log"?

sinelaw
  • 16,205
  • 3
  • 49
  • 80
jahuer1
  • 377
  • 4
  • 15
  • A simplistic approach would be to run the application with a redirection in the command line (`myapp.exe > logfile.txt`) – sinelaw Apr 27 '12 at 15:56
  • Can you ask everyone to use built in .Net logging/tracing infrastructure? (or any other particular logging library). – Alexei Levenkov Apr 27 '12 at 16:07
  • The DLL is: the original apache fop jar transfered to DLL by IKVM. Done just the common way as described on http://www.ikvm.net/ . – jahuer1 Apr 30 '12 at 09:39
  • @sinlaw: 1. unfortunately I don't have the control how the application is called. 2. This way didn't function here :-( {test on my machine} – jahuer1 Apr 30 '12 at 10:10

0 Answers0