Configuring the application to be profiled without changing the application code
While the easiest way to prepare the application to be profiled is to just call NHibernateProfiler.Initialize(), this is often not a desirable way of doing things, since adding / removing the profiler requires changing the application code.
Therefore, I also made it possible to configure the application without this explicit initialization approach. The method of doing so is:
- Create a log4net.config file with the following content to log to a live instance of the NHibernate Profiler:
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="NHProfAppender"
type="HibernatingRhinos.Profiler.Appender.NHibernate.NHProfAppender,
HibernatingRhinos.Profiler.Appender.NHibernateLog4Net">
<sink value="tcp://127.0.0.1:22897" />
</appender>
<logger name="HibernatingRhinos.Profiler.Appender.NHibernate.NHProfAppender.Setup">
<appender-ref ref="NHProfAppender"/>
</logger>
</log4net> - Create a log4net.config file with the following content to log to a file that can be later loaded into the NHibernate Profiler:
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="NHProfAppender"
type="HibernatingRhinos.Profiler.Appender.NHibernate.NHProfOfflineAppender,
HibernatingRhinos.Profiler.Appender.NHibernateLog4Net" >
<file value="nhprof_output.nhprof" />
</appender>
<logger name="HibernatingRhinos.Profiler.Appender.NHibernate.NHProfAppender.Setup">
<appender-ref ref="NHProfAppender"/>
</logger>
</log4net> - Add a reference to the following dll's:
- HibernatingRhinos.Profiler.Appender.dll
- HibernatingRhinos.Profiler.Appender.NHibernateLog4Net.dll
- In the application startup, call:
log4net.Config.XmlConfigurator.Configure(new FileInfo("/path/to/log4net.config"));
The logger exposes the following properties to allow to configure its behavior (mostly regarding performance):
- Stop doing fixups for runtime generated code stack traces.
<dotNotFixDynamicProxyStackTrace value="true"/>
- Stop capturing all stack traces.
<skipCapturingStackTraces value="true"/>