Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I wrap calls to Debugger.Log() in #if (DEBUG)?

Is it necessary to wrap calls to Debugger.Log() in the #if (DEBUG) preprocessor directive for the purpose of code optimization, or will the C# compiler still produce optimized code when building the RELEASE configuration?

like image 423
Dan Stevens Avatar asked Jun 11 '12 13:06

Dan Stevens


People also ask

What do you do with a debug log?

Use debug logs to track events that occur in your org. Debug logs are generated when you have active user-based trace flags, when you run Apex tests, and when executed code or API requests include debugging parameters or headers.

What is log file debugging?

Debug logs are system-generated logs that are sent to your Dashboard along with every new conversation. They only appear if your developers have configured them in the SDK for a given game/app version. When configured, they appear under the metadata tab in the Issue details pane.

How do you use Tracepoints?

You can set tracepoints by specifying an output string under the Action checkbox in the Breakpoint Settings window. To initialize a tracepoint, first click on the gutter to the left of the line number where you want to set the tracepoint. Hover over the red circle and then click the gear icon.

How do I view logs while debugging in Visual Studio?

If you want to see variable values while debugging the application you can use "Quick Watch", "Add Watch" or Autos. In Visual Studio 2010, the Autos Window displays variables on the current line and one line above and below. Look at here for more debugging window help. Show activity on this post.


1 Answers

There is not any kind of optimization on this call in RELEASE mode.

The call is present in IL. The only difference is that it has no any effect if there is not a DEBUGGER present.

From documentation Debugger.Log:

If there is no debugger attached, this method has no effect.

I would suggest to measure your app's performance and after that choose the steps to follow.

If there is no significant difference (from your app's point of view), I would leave that log as is.

In this way, in the moment of need, you can attach to your app with debugger and get messages you might need from the log, as Debugger.Log would work at that point.

like image 112
Tigran Avatar answered Oct 20 '22 21:10

Tigran