Friday, August 06, 2010

Sitecore Logging Part 4. Integration with Log4Net Dashboard.

In my older posts I was showing how to teach Sitecore CMS to log events into a SQL Server database, today it is time to reveal the last part of this blog series.
Having everything in SQL is great, and it already enables you run queries, but wouldn’t it better to have some sort of a visual dashboard showing you all new events, highlighted by severity and type, and also let you filter those?

I liked that idea and decided to try out how this Log4Net Dashboard component by FaktNet AS can accomplish this.
The download is free for development workstations, which is awesome.
The installation was quite simple, it is just an ASP.NET application, really. I configured it as a separate site in IIS to simplify things.
The configuration was quite easy too:
1. Configure the LocalSql datasource where you need to specify the connection string to your SQL Server database with the Log table:
<datasource name="LocalSql"
       Description="Log4Net logging events stored in the SQL Server database on the local machine">
 <provider type="L4NDashSqlServerProvider.SqlServerProvider" 
           assembly="L4NDashSqlServerProvider, Version=2.4, Culture=neutral"/>
  <predefinedsearchfilter value="Filters\DefaultSearchFilters.xml"/>
     <connectionstring value="user id=sa;password=*;Data Source=(local);Database=db"/>
       <TableName value="Log" />
               Defines timeout (in seconds) for sql commands, if the log table is huge or the database server
               is "jammed" you may need to increase this 
            <SqlCommandTimeout value="60"/>

            <!--Max number of rows to retrieve for the log rows panel-->
            <MaxNoOfRowsToRetrieve value="1000"/>

2. Verify that the “TableName” and column reference correspond to your table in SQL:
<NameMapping TableName="Log"
             ExceptionColumn="Exception" />

3. If you extended the ADONetAppender as I showed previously, define the following custom columns:
<customcolumn name="SCUser">
   <label value="User Name" />
   <rowstabledisplay value= "yes" />
   <rowsdetaildisplay value= "yes" />
   <filter value="yes" />

<customcolumn name="SCItemId">
   <label value="Item Id" />
   <rowstabledisplay value= "yes" />
   <rowsdetaildisplay value= "yes" />
   <filter value="yes" />

<customcolumn name="RawUrl">
   <label value="Raw Url" />
   <rowstabledisplay value= "yes" />
   <rowsdetaildisplay value= "yes" />
   <filter value="yes" />

Now you can run the Log4Net Dashboard application, but before you can view any of the Sitecore logs from the database, you need to make sure to select “LocalSql” as your default datasource:
That’s all – refresh the application and enjoy nice visualization of how your app is doing:
Now that we have everything running smoothly, let’s add another piece. Let’s bring this application to Sitecore desktop. The easiest way to do it is to change the configuration of the default Sitecore Logging application. Specifically:
1. Login to Desktop –> core database.
2. Navigate to /sitecore/content/Applications/Reports/LogViewer:
3. Paste the URL of your Log4Net Dashboard application into the “Application” field:
Now refresh the browser and open Log Viewer application:
Here you go – refreshed Log Viewer available from Sitecore desktop interface:
In production, I’d disabled anonymous access to this application and probably added some IP restrictions too, so this app can safely be access from outside.
Of course for running in production, you will need to get the license from the Log4Net Dashboard vendor.

I suggest you try it and check out this video to see more of the specific capabilities of this tool:
That’s all, folks!


Vangansewinkel Benjamin said...

Thank you very much for this usefull serie of post about log4net

Benjamin V

kiran Patil said...

Hello Alex,

Thanks for the post! - nice and very useful.

We are also thinking to use Log4NetDashboard. But rather than using SqlAppender, we are thinking to use XmlAppender. As sql will have its own challenges like DB Connectivity, Size etc. But before using XmlAppender Just wanted to have your expert opinion on it. What do you suggest?

Also, we I read some where that XmlAppender is not thread-safe [I know log4Net is thread-safe]. Is it the case?

Hoping for favorable reply.

Kiran Patil

Alex Shyba said...

Hi Kiran,

I have not tried the XmlAppender, so I cannot really provide a helpful comment. One of the good things about having the logs in the database is that you can use SQL for reporting. Plus in a web farm scenario, you can have a single repository for all production web servers. That could be handy.
Writing logs to the file system seems like a great idea overall for dev instances. For production I would still go with database. I don't think that size is a big issue. In terms of connectivity, if you are running clustered environment in production, that should not be an issue either.

jp said...

How about CM/CD enviroment. Can I in CM easily view logs from CD's and CM's?