In Umbraco we use the underlying logging framework of Serilog.
Out of the box we write a JSON log file that contains a more rich logfile, that allows tools to perform searches & correlation on log patterns a lot easier.
The default location of this file is written to umbraco/Logs
and contains the Machine name, along with the date too:
umbraco/Logs/UmbracoTraceLog.DELLBOOK.20210809.json
Serilog is a logging framework that allows us to do structured logging or write log messages using the message template format. This allows us to have a more detailed log message, rather than the traditional text message in a long txt file.
Here is an example of the same log message represented as JSON, you can see here we have much more information that would allow us to search & filter logs based on these properties with an appropriate logging system.
To learn more about structured logging and message templates you can read more about it over on the https://messagetemplates.org website or alternatively watch this video from the Serilog creator - https://www.youtube.com/watch?v=OhmNp8UPEEg
Umbraco writes log messages, but you are also able to use the Umbraco logger to write the log file as needed, so you can get further insights and details about your implementation.
Here is an example of using the logger to write an Information message to the log which will contain one property of Name which will output the name variable that is passed into the method
The example below uses UmbracoApiController which is obsolete in Umbraco 14 and will be removed in Umbraco 15.
If you are Logging and using the MiniProfiler, you can inject IProfilingLogger
that has a reference to both ILogger and IProfiler.
The incorrect way to log the message would be use string interpolation or string concatenation such as
The bad examples above will write to the log file, but we will not get a separate property logged with the message. This means we can't find them by searching for log messages that use the message template We are saying hello to {Name}
Serilog uses levels as the primary means for assigning importance to log events. The levels in increasing order of importance are:
Verbose - tracing information and debugging minutiae; generally only switched on in unusual situations
Debug - internal control flow and diagnostic state dumps to facilitate pinpointing of recognised problems
Information - events of interest or that have relevance to outside observers; the default enabled minimum logging level
Warning - indicators of possible issues or service/functionality degradation
Error - indicating a failure within the application or connected system
Fatal - critical errors causing complete failure of the application
Serilog can be configured and extended by using the .NET Core configuration such as the AppSetting.json files or environment variables. For more information, see the Serilog config article.
Learn more about the logviewer dashboard in the backoffice and how it can be extended.
This is a tool for viewing & querying JSON log files from disk in the same way as the built in log viewer dashboard.
Umbraco ships with the following Serilog projects, where you can find further information & details with the GitHub readme files as needed.
If you are interested in learning more then the following resources will beneficial:
Seq This is free for a single machine such as your own local development computer