Debugging
During the development of your Umbraco site you can debug and profile the code you have written to analyse and discover bottlenecks in your code.
To perform proper debugging on your site you need to set your application to have debug enabled. This can be done by setting Umbraco:CMS:Hosting:Debug="true"
for example in the appsettings.json
file:
Debug should always be set to false in production.
Tracing
Tracing and trace logging are two names for the same technique. You need to configure which log messages you want to log.
Enabling Trace Logging
Do not enable trace logging in your production environment! It reveals an awful lot of (sensitive) information about your production environment.
We recommend at least logging the following namespace at minimum (Verbose) level to enable valuable trace logging. Thereby you will have information about all endpoints that have been executed.
The logged messages can as always be monitored in the log viewer in backoffice
MiniProfiler
Umbraco includes the Mini Profiler project in its core (see https://miniprofiler.com for more details). The MiniProfiler profiles your code method calls, giving you a greater insight into code duration and query time for (for example) underlying SQL queries. It's great for tracking down performance issues in your site's implementation.
Displaying the MiniProfiler
To display the profiler ensure that the configuration Umbraco:CMS:Hosting:Debug
is set to true
in the appSettings.json file. Thereafter you can add ?umbDebug=true
to the query string of any request.
Also, ensure your template calls @Html.RenderProfiler()
as one of the last things.
![](https://docs.umbraco.com/~gitbook/image?url=https%3A%2F%2F65787334-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F8h0xdoteqcFVV1pGZgk0%252Fuploads%252Fgit-blob-db39a3caab102f81e600a1707b012681bb0f5f09%252Fv8-miniprofiler-view.png%3Falt%3Dmedia%26token%3D8b5fa35b-a8f8-4d3b-bc49-103371a3b35e&width=768&dpr=4&quality=100&sign=2fb25e66&sv=1)
If you click 'Show Trivial' you can seen the kind of detail the MiniProfiler makes available to you about the execution path of your page:
![](https://docs.umbraco.com/~gitbook/image?url=https%3A%2F%2F65787334-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F8h0xdoteqcFVV1pGZgk0%252Fuploads%252Fgit-blob-7b36e615056c799fe8001d68c5a408a8e706cb13%252Fv8-miniprofiler-trivial.png%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=8b65121&sv=1)
and any underlying SQL Statements that are being executed for a part of the execution:
![](https://docs.umbraco.com/~gitbook/image?url=https%3A%2F%2F65787334-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F8h0xdoteqcFVV1pGZgk0%252Fuploads%252Fgit-blob-ea1a4c208c187cf27558bf2083b1e66e1150b166%252Fv8-miniprofiler-sql-trigger.png%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=acf40ea6&sv=1)
![](https://docs.umbraco.com/~gitbook/image?url=https%3A%2F%2F65787334-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F8h0xdoteqcFVV1pGZgk0%252Fuploads%252Fgit-blob-9535949c1e3293ab18b97ac1842fc29c13c5b228%252Fv8-miniprofiler-sql-details.png%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=f5ead566&sv=1)
Writing to the MiniProfiler
If you feel like a part of your application is slow you can use the MiniProfiler in your code to test the speed of it.
All you have to do is inject the IProfiler interface and add a step around your logic:
and now in the profiler you can see:
![](https://docs.umbraco.com/~gitbook/image?url=https%3A%2F%2F65787334-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F8h0xdoteqcFVV1pGZgk0%252Fuploads%252Fgit-blob-cd40b9f107cf4aa8deb1f84205297aee253c52aa%252Fv8-miniprofiler-write.png%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=e1c8559&sv=1)
Umbraco Productivity Tool - Chrome Extension
If you are using the Google Chrome browser you can install this Umbraco Productivity Tool Chrome Extension.
This will allow you to quickly switch between debugging with the MiniProfiler, Trace viewer and normal mode.
![](https://docs.umbraco.com/~gitbook/image?url=https%3A%2F%2F65787334-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F8h0xdoteqcFVV1pGZgk0%252Fuploads%252Fgit-blob-922074898af98704af5260847f33da828a5a5e36%252Fchrome-tool.png%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=5680fa70&sv=1)
Learn how Umbraco writes log files and how you can write to them.
Last updated