0

Being relatively new to ASP.NET, I took over a large project, and I want to debug my Global.asax.cs using System.Diagnostics.Debug.WriteLine("foo"); or Console.WriteLine("bar");. The strange thing is that I do not find the output foo or bar, I was expecting it in the Output window of my Visual Studio (Professional 2017) or in the F12-browser console, but there is nothing.

My code reads:

namespace API
{
    public class WebApiApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            // different stuff
            System.Diagnostics.Debug.WriteLine("foo");
            Console.WriteLine("bar");
        }
    }
}

Is there some configuration within Visual Studio I have to adjust? The strange thing is, that for other projects of the same solution, I do see output.

References

B--rian
  • 5,578
  • 10
  • 38
  • 89
  • @Wiktor Zychla: My question rephrased: Is logging within Global.asx.cs any different than logging elsewhere in my project? For me it currently looks like this. As stated in my question, console output does in principle work in my VS solution, just not in the file I asked about. – B--rian Jan 15 '20 at 11:11
  • Avoid using `Console.WriteLine` in a web app. You could be tricked it works in your VS in some specific scenarios but in general, it's useless, it won't work in a production environment where the app doesn't have any console to write on. As for diagnostics - you have to first attach a listener and then it should always work. – Wiktor Zychla Jan 15 '20 at 11:26
  • @WiktorZychla: I figured, that the root problem is actually a different one, so I asked a different question: https://stackoverflow.com/questions/59753445/why-is-one-of-my-global-asax-cs-file-in-my-asp-net-solution-with-two-startup-p – B--rian Jan 15 '20 at 14:30
  • Would you consider reopening the question, please? I would like to clarify in an answer that my issue is not about how-to-debug-output, but rather why-does-debug-not-work-in-a-specific-file. – B--rian Jan 15 '20 at 14:33

0 Answers0