Database logging with Insite

To research performance or stability issues with Insite it is helpful to log the database activity. Logging the database with Insite depends on which version you are using. If you are using the latest version, 4.2, then you will want to use the Entity Framework change. If you are using version 4.1 or earlier, you will want to use the Nhibernate config change. The reason why we have two different approaches is because Insite switched the database ORM from NHiberante to Entity Framework in version 4.2.

Entity Framework Configuration Change (Insite version 4.2 or greater)

To enable logging in Insite 4.2, add the following configuration section to the web.config. In the below example we pass two parameters. The 1st parameter is the path to save the log file. The 2nd parameter is the log file if overwritten or appended. The log file will be overwritten if the parameter is false. If the 2nd parameter is true then the file will be appended.

      <interceptor type="System.Data.Entity.Infrastructure.Interception.DatabaseLogger, EntityFramework">
          <parameter value="C:\temp\EntityFrameworkLogOutput.txt"/>
          <parameter value="true" type="System.Boolean"/>

NHibernate Configuration Change (Insite version 4.1 or earlier)

Previous version of Insite 4.1 or earlier used NHibernate as the database ORM. To enable logging in NHibernate we will need to use the file appender for NHibernate logger.

    <logger name="NHibernate">
      <level value="ALL"/>
      <appender-ref ref="file"/>

Out of box the file will be saved to the App_Log folder using logfile.txt as the filename. The Log4Net file appender is used to specify how the files are generated.

  <appender name="file" type="log4net.Appender.RollingFileAppender">
    <appendToFile value="true" />
    <rollingStyle value="Size" />
    <maxSizeRollBackups value="10"/>
    <maximumFileSize value="10MB"/>
    <countDirection value="1"/>
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"/>

After the database logging has been enabled you will have the ability to see what is being sent to the database and understand the context of any database errors generated. Another benefit is the ability to identify what queries are taking a long time to run. After you have identified the section of database code performing slow you can add caching if the data does not change frequently. If the data changes frequently then you could update the query to minimize how many rows are returned.

The above information will now help you to identify and resolve issues related to performance and reliability with Insite.