This project is read-only.
Project Description
NHTrace is a tool for tracing sql commands executed by NHibernate with syntax highlighting.

screenshot.png

Details

NHTrace listen for events logged by log4net, so, in order to trace, first you need to configure log4net on the application where NHibernate executes the sql commands. An example of that configuration can be found here.

NOTE: currently NHTrace only supports log4net MsmqAppender, for more information about how to configure Microsoft Message Queue and log4net MsmqAppender, please see Installing and configuring Microsoft Message Queue and log4net MsmqAppender

To highlight the sql commands, NHTrace uses these two javascript libraries:
SHJS
Google's Prettify

To choose between them, change the "templatePath" key to the correct template.html file in the application configuration file (NHTrace.exe.config).
    <add key="templatePath" value=".\Templates\shjs\template.html"/>
    <!--<add key="templatePath" value=".\Templates\prettify\template.html"/>-->

Other libraries could be used, here is a good list of different syntax highlighting libraries

Features

Functions of the buttons in the toolbar

toolbar.png
  • Toggle logging on/off
  • Clear log
  • Refresh log
  • Save log
  • Toggle always on top on/off
  • Toggle show process name on/off
  • Toggle status bar visibility on/off

Configuration

This settings have to be configured on the NHTrace.exe.config file

    <add key="logCharSize" value="20000"/>
    <add key="templatePath" value=".\Templates\shjs\template.html"/>
    <!--<add key="templatePath" value=".\Templates\prettify\template.html"/>-->

  • logCharSize: amount of characters to show on the log (high values may cause some instability)
  • templatePath: path (can be relative or absolute) to the template.html file used to render the messages with syntax highlighting

Updates
  • NHTrace release 47571

In this release the messages can be viewed in plain text and the sql commands can be copied with formatting, while you can choose to copy the command as it is or replace the parameter values inside the command as well. See screenshot below

screenshot2.png
  • "Copy formatted sql" stores the following text in the clipboard
    INSERT 
    INTO
        "Product"
        (Name, UnitPrice, Discontinued, Id) 
    VALUES
        (@p0, @p1, @p2, @p3);
    @p0 = 'Apple0', @p1 = 0.25, @p2 = False, @p3 = 1001
  • "Copy sql and replace parameters" stores the following text in the clipboard
    INSERT 
    INTO
        "Product"
        (Name, UnitPrice, Discontinued, Id) 
    VALUES
        ('Apple0', 0.25, False, 1001);

NOTE: multiple lines can be selected also

Credits

Author: Jorge Rowies

Google profile: http://www.google.com/profiles/jorge.rowies
Blog: http://jorgerowies.blogspot.com/
Ohloh: http://www.ohloh.net/accounts/jorgerowies

Some log4net receivers developed by Rémy Baudet in Log2Console were modified to be used by NHTrace

Any feedback about this tool will be appreciated

Last edited Jun 9, 2010 at 1:40 AM by jorgerowies, version 30