Diplo Trace Log Viewer for Umbraco Blog post

From around Umbraco 4.10 the way Umbraco logs information was changed. A new logging class was created in Umbraco.Core.Logging called LogHelper that utilises an implementation of Log4Net.

Previously all logs were generated in the database inside the umbracoLog table. However, this new class logs to plain text files which are rotated daily and stored in the /App_Data/Logs/ folder within your Umbraco site. If you look in there you should see a file called UmbracoTraceLog.txt. This is the current log file, whilst the older files with a date suffix are the historical logs.

Anatomy Of a Log File

If you open the UmbracoTraceLog.txt file you will see it's just a plain text file that contains log entries that look similar to the following:

2013-06-23 17:39:00,021 [11] INFO  Umbraco.Core.CoreBootManager - [Thread 5] Umbraco application starting
2013-06-23 17:39:00,039 [11] INFO  Umbraco.Core.PluginManager - [Thread 5] Determining hash of code files on disk
2013-06-23 17:39:00,044 [11] INFO  Umbraco.Core.PluginManager - [Thread 5] Hash determined (took 4ms)
2013-06-23 17:39:00,203 [11] INFO  Umbraco.Core.PluginManager - [Thread 5] Completed resolution of types of Umbraco.Core.PropertyEditors.IPropertyEditorValueConverter, found 0 (took 151ms)
2013-06-23 17:39:00,209 [11] INFO  Umbraco.Core.PluginManager - [Thread 5] Completed resolution of types of Umbraco.Web.Mvc.SurfaceController, found 0 (took 2ms)
2013-06-23 17:39:00,218 [11] INFO  Umbraco.Core.PluginManager - [Thread 5] Completed resolution of types of Umbraco.Core.Media.IThumbnailProvider, found 3 (took 2ms)
2013-06-23 17:39:00,220 [11] INFO  Umbraco.Core.PluginManager - [Thread 5] Completed resolution of types of Umbraco.Core.Media.IImageUrlProvider, found 1 (took 1ms)
2013-06-23 17:39:00,240 [11] INFO  Umbraco.Core.PluginManager - [Thread 5] Completed resolution of types of umbraco.interfaces.IApplicationStartupHandler, found 8 (took 3ms)
2013-06-23 17:39:00,286 [11] INFO  Umbraco.Core.CoreBootManager - [Thread 5] Umbraco application startup complete (took 262ms)
2013-06-23 17:39:00,294 [11] INFO  Umbraco.Core.PluginManager - [Thread 5] Completed resolution of types of umbraco.interfaces.IApplication, found 7 (took 5ms)
2013-06-23 17:39:00,451 [11] INFO  Umbraco.Core.PluginManager - [Thread 5] Completed resolution of types of umbraco.interfaces.ITree, found 27 (took 3ms)
2013-06-23 17:39:00,774 [11] ERROR Umbraco.Web.UmbracoApplication - [Thread 5] An unhandled exception occurred
System.ApplicationException: The current httpContext can only be set once during a request.
   at Umbraco.Web.UmbracoContext.set_Current(UmbracoContext value)
   at Umbraco.Web.UmbracoContext.EnsureContext(HttpContextBase httpContext, ApplicationContext applicationContext, Boolean replaceContext)
   at Umbraco.Web.UmbracoModule.BeginRequest(HttpContextBase httpContext)
   at Umbraco.Web.UmbracoModule.b__6(Object sender, EventArgs e)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
2013-06-23 17:39:06,414 [11] INFO  Umbraco.Web.UmbracoApplication - [Thread 5] Application shutdown. Reason: HostingEnvironment

As you can see, log files contain the following information for each entry:

  • The date and time of the log entry
  • A number in square brackets that has something to do with the thread that was running (?)
  • The name of the .NET type that generated the log entry (ie. the name of the class from within which the call to write to the log was made)
  • The logging level (ie. INFO, WARNING, ERROR)
  • Another thread reference (?)
  • The message being logged (which, in the case of an error, may be an exception stack trace)

The format of this log is defined in /config/log4net.config and can be tweaked there.

Whilst these log files are quite easily human readable, they aren't viewable from within Umbraco itself. That means to view them you need to have direct access to the server and to the /App_Data/Logs/ folder within your site. Another drawback of the new format is that they aren't easily sortable or filterable - in fact, the new log file format isn't at all easy to parse since the fields and entries are not delimitted in any way.

Introducing Diplo Trace Log Viewer

To get around the problem of not being able to (easily) view log files I've written a small Umbraco package that installs itself into the Developer tree (in Umbraco 7) or as a Dashboard panel (in Umbraco 6). It allows you to select, view, sort, filter and search log files.

Umbraco 7 Version

Umbraco 7 Version

Umbraco 6 Version

Umbraco 6 Version

Give Me The Download!!!!!

You can download and install the package (it's free!) from http://our.umbraco.org/projects/developer-tools/diplo-trace-log-viewer

There is also a NuGet package version which you can install - with thanks to Jeavon Leopold.

If you are really nosey you can get the source code (for the Umbraco 7 version) on GitHub.

Note: The latest version (2.x) has been rewritten from scratch for Umbraco 7 using AngularJS and WebApi controllers.

Also note I have another log viewer package for the umbracoLog table data - Diplo Audit Log Viewer.


14 Comments


Abel Braaksma Avatar

This seems like an awesome package, but after installing it in Umbraco 7.4.3, the Developer tree does not show the extra "Trace log" entry. I did a republish, just to be sure. But perhaps I need to do something else as well, but I couldn't find it here, nor on other websites mentioning Diplo Trace Log Viewer.



Abel Braaksma Avatar

It is not uncommon that the Bin-directory on production servers is read only. If that happens, no error will be shown when you install this package, however, you won't see the product appear in the tree either.


To resolve, add it to your project as a NuGet package. Make sure to also check in the changes after the first build, because this NuGet package will change your project file and your build server needs to see this changed project file (it adds the reference), or it will still not work.



Abel Braaksma Avatar

If you have deployed your Umbraco project in an application dir (as opposed to the root of a website) you will find that Diplo Trace Logger works only partially. Viewing the details of an error doesn't work. You can fix this by changing the template that contains a hard-coded, non-relative reference to /App_Plugins/DiploTraceLogViewer/backoffice/diplotracelog/detail.html. Replace the / with ~/ and you are done (not tested yet, we are still researching whether this fully fixes it, but bottom line is, in this package, it would be better if all references are relative).


Abel Braaksma Avatar

(last note) It looks like the ~/ solution doesn't work, as it is part of the js-file EditController.js, and the server won't recognize it. This should eventually be dynamically resolved (by resolving the actual root appdir), but for us it presently works by using template: '../App_Plugins/DiploTraceLogViewer/backoffice/diplotracelog/detail.html' instead. The ".." would also work with existing installations that use the root.


Maybe this helps someone else as well, or may become part of the next version of this otherwise excellent package ;)


Rasmus Eeg Møller Avatar

Does it work with all *.txt files in ~/App_Data/Logs/ ? I'm asking because i have custom RollingFileAppenders i many projects, to seperate Umbraco errors from integration errors.


Dan Diplo Avatar

Hi Rasmus,


No, sorry, it only reads files that are in the Umbraco format - it can only parse log files that use the format that Umbraco does. It would be possible to modify the code so it could read other file formats. The code that reads logfiles can be found in:


https://github.com/DanDiplo/UmbracoTraceLogViewer/blob/master/Diplo.TraceLogViewer/Services/LogFileService.cs 


As you can see, it only matches ones with a specific format.


 


AntoXaPRO Avatar

Hi, thanks for the plugin! Good stuff!


Davo Avatar

Hi, Is there any way of applying permissions to the plugin so it can be shown in the dashboard in Umbraco 7? I've got it showing in the dashboard but only if the user has access to the developer tab. Thanks


Dan Diplo Avatar

Hi Davo,


No, it was specifically designed for the Developer section I'm afraid. The reason is the log contains lots of technical info and also, potentially, stuff that should remain secure and not be seen by editors.


If you really wanted this you could clone the project and change the lines here to be something else.


Davo Avatar

Legend! Thanks so much


Daniel Matthews Avatar

I tried installing this via the backoffice UI and it failed to install and now my Developer tab is broken (wont render the tree). Can someone confirm how to *manually* delete this plugin when it is not rendering in the UI? Thanks


Dan Diplo Avatar

Hi Daniel. Sorry you had an issue - it's not something that other people have reported, so may be related to your Umbraco setup. If you use a container (dependency injection) then you'll need to register the controller manually, which is sometimes an issue. If you have more details you can report the issue at https://github.com/DanDiplo/UmbracoTraceLogViewer/issues 


To manually remove it then you can do this:


Delete the Diplo.TraceLogViewer.dll from the /bin/ folder.


Delete the DiploTraceLogViewer folder from the /App_Plugins/ folder.


You can also (optionally) remove the diploTraceLog entry in the /config/trees.config folder 


 


Fiona Lawson Avatar

Great package - is ti possible to export the logs (to save grabbing them off the server?) thanks Fiona


Dan Diplo Avatar

Hi Fiona,


Exporting logs isn't something I was planning on adding. Sorry!


 

Just fill in the form and click Submit. But note all comments are moderated, so spare the viagra spam!

Tip: You can use Markdown syntax within comments.