Should one go to Production with a DEBUG Build?
Here's a question that I'd really like to stir up some talk/comments/feedback.
Should one go live with a .NET (in this case ASP.NET) app compiled as DEBUG? Some folks have claimed that whatever speed you might gain is pale compared to the usefulness of the occasional late night production debugging session. A RELEASE build strips out Debug.Write calls, etc., but we use Log4net exclusively, so that doesn't affect us.
Thoughts and comments, oh wise bloggers? Is this clever, controversial, or stupid?
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
About Newsletter
1 void SomeMethod() {
2 SomeClass someVariable = GetSomeHugeObjectGraph();
3 if (ImportantClass.ShouldIKeepDoingSomething) {
4 SomeMethod()
5 }
6 }
Code compiled in release mode may release someVariable's reference to the huge object graph at line 3 since it isn't used again. In debug mode the references are kept since you may want to inspect the variable later. Since our code is recursive, this could have pretty significant ramifications. I thought this was only while the debugger was attached, but Doug Reilly set me straight[1].
[1] http://weblogs.asp.net/jkey/archive/2003/12/19/44810.aspx
Have you thought about EIF for this same purpose?
Seriously, though, Log4Net has been a CHAMP. I LOVE IT.
What about the FAQ gave you the impression it wasn't useful in Production? I plan to turn the loglevel to FATAL and use it.
Please note I have never done this, but it seems feasible.
Stack trace is written to log4net log, not shown to user, of course.
"Is log4net a reliable logging system?
No. log4net is not reliable. It is a best-effort and fail-stop logging system"
to be sure, the FAQ was written in 2002. I guess it just made me look twice.
You can have the best of both worlds with a rather neat trick. The major differences between the default debug build and default release build are that when doing a default release build, optimization is turned on and debug symbols are not emitted. So:
Step 1: Change your release config to emit debug symbols. This has virtually no effect on the performance of your app, and is very useful if (when?) you need to debug a release build of your app.
Step 2: Compile using your new release build config, i.e. *with* debug symbols and *with* optimization. Note that 99% of code optimization is done by the JIT compiler, not the language compiler, so read on...
Step 3: Create a text file in your app's folder called xxxx.exe.ini (or dll or whatever), where xxxx is the name of your executable. This text file should initially look like:
[.NET Framework Debugging Control]
GenerateTrackingInfo=0
AllowOptimize=1
Step 4: With these settings, your app runs at full speed. When you want to debug your app by turning on debug tracking and possibly turning off (CIL) code optimization, just use the following settings:
[.NET Framework Debugging Control]
GenerateTrackingInfo=1
AllowOptimize=0
Hope this helps,
Mark
EIF Shortcomings:
The log file viewer is very limited:
Doesn’t sort correctly (because everything is treated as a string; this ruins timestamp sorting)
No filters
Doesn’t remember UI layout
No way to segment data (i. e., a new log every day)
Finicky configuration
Must be separately installed on deployment platform
Event sources must be pre-created using EventLog.CreateEventSource
Good things about EIF:
Handles large amount of data and high volumes well
Stable once configured correctly
Comments are closed.
Someone enumerated the several "bad things" about debug builds in production; unfortunately I don't remember who. It was either Rico[1] or someone at PDC. If it was Rico, you can check his blog and if it was PDC you can check out the presentations online[2]. (Minor gripe: We paid something like $200 or $500 for those conference DVDs, the content of which is available online for free and also available for free with the Longhorn Migration kit. What's up with that?)
[1] http://weblogs.asp.net/ricom/
[2] http://microsoft.sitestream.com/PDC2003/Default.htm