Search code examples
asp.netiis-express

How to capture IIS Express output when run from Visual Studio 2010 SP1?


If you run IIS Express from the command line, anything you write Console.Out in your web app is displayed in the command line output. This is very handy for trouble shooting LINQ to SQL translation issues if you set DataContext.Log = Console.Out. However, if you check "Use IIS Express" in the web project properties in VS 2010 SP1 you never see the command line.

Can you redirect IIS Express Console.Out to a log file or something?


Solution

  • I found a way to write directly to the Debug Console window via damieng's blog:

    class DebugTextWriter : System.IO.TextWriter {
       public override void Write(char[] buffer, int index, int count) {
           System.Diagnostics.Debug.Write(new String(buffer, index, count));
       }
    
       public override void Write(string value) {
           System.Diagnostics.Debug.Write(value);
       }
    
       public override Encoding Encoding {
           get { return System.Text.Encoding.Default; }
       }
    }
    

    You can attach it to a DataContext like you would with Console.Out:

    #if DEBUG
       db.Log = new DebugTextWriter();
    #endif
    

    http://damieng.com/blog/2008/07/30/linq-to-sql-log-to-debug-window-file-memory-or-multiple-writers