0

I'm using Visual Studio and developing ASP.net MVC application, I want to log some text when I run my app in Run Without Debugging state for debugging purposes.

I don't know what to do! I can log my texts into a log file using System.StreamWriter class, but is there a class in .net framework that does this?

Mohamad Shiralizadeh
  • 8,329
  • 6
  • 58
  • 93

2 Answers2

1

Litterally the first result in google for "C# detect debugger" : Use Debugger.IsAttached as described here : https://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.isattached(v=vs.110).aspx

And I'd suggest that you look into log4net for your logs instead of using streamwriters, it'll give you much more flexibility.

Foxtrot
  • 607
  • 4
  • 10
  • @ Mohamad, I agree with Foxtrot's suggestion, log4net would be a good answer if you want to get the output information without debugging the app. Of course, generally we collect the debugging logs in the output window:) – Jack Zhai Dec 16 '16 at 09:55
1

Generally the StreamWriter and Log4Net are the workaround I often use:

For the Exception messages, some community members think about using custom code with StringBuilder like this case:

How to Log Exception in a file?

How to write log file in c#?

If they are really not the answer you want to use, I suggest submit a feature request to the product team, of course, if you accept this suggestion, I can help you submit it:)

Community
  • 1
  • 1
Jack Zhai
  • 6,230
  • 1
  • 12
  • 20