2

i need to output some debugging information from code on a web-site.

How can i call OutputDebugString from an ASP.net web-site, and have it appear to users running DbgView?

Note: Web-sites do not support System.Diagnostics.Trace.TraceWarning(...).

3
  • Take a look at this and let me know if this solves your issue: blog.aggregatedintelligence.com/2010/12/…. Commented Oct 1, 2012 at 18:17
  • That is the default listener for Systems.Diagnostics TraceSource. The trace will appear in DbgView on the server. You said "Users", you don't mean the people visiting your website, right? For that you'd have to somehow write a custom listener to write to the HTML response. Commented Oct 17, 2012 at 20:52
  • @MatthewMartin Oh no, i meant someone (i.e. me) on the server running DbgView. i know that Windows doesn't support letting you see OutputDebugStrings that were generated by a service - hence the question. Commented Oct 18, 2012 at 2:11

1 Answer 1

-1

Okay, here is a complete example. It's a console but the principles and the code are much the same. I couldn't test capturing from OutputDebugString on my machine today because I don't have admin rights. On a server, you'd write to TextWriterTraceListener instead of a console. If you can't write and read from OutputDebugString using pinvoke, may the customer doesn't have the rights or the app doesn't have the necessary rights.

Also! If the Debug.WriteLine isn't showing up, maybe the website is compiled in RELEASE mode and DEBUG isn't define. TRACE by default is defined for RELEASE And DEBUG. TraceSource writes to OutputDebugString unless you've cleared the default listener, which a lot of people do as a matter of habit since OutputDebugString in my experience can slow things down esp if you aren't actually looking at the output at the moment.

using System.Diagnostics;
using System.Runtime.InteropServices;

namespace TraceToOutputDebugString
{
    class Program
    {
        [DllImport("kernel32.dll")]
        static extern void OutputDebugString(string lpOutputString);

        static void Main(string[] args)
        {
            //Put these lines in your asp.net Page
            OutputDebugString("Hello from Pinvoke OutputDebugString");
            TraceSource trace = new TraceSource("app");
            trace.TraceInformation("Hello from TraceSource");
            Trace.TraceInformation("Hello from 1.1 Trace.TraceInformation");
            Debug.WriteLine("Hello Debug.WriteLine");
            System.Console.ReadKey();
        }
    }
}

And here is the config.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.diagnostics>
        <sources>
            <source name="app" switchName="app">
                <listeners>
                    <add name="Console" type="System.Diagnostics.ConsoleTraceListener"/>
                </listeners>
            </source>
        </sources>
        <switches>
            <add name="app" value="Information"/>
        </switches>
        <trace>
            <listeners>
                <add name="Console" type="System.Diagnostics.ConsoleTraceListener"/>
            </listeners>
        </trace>
    </system.diagnostics>
</configuration>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.