I'm having an issue in where records occasionally go missing from our production database. This is a .NET MVC 2 app with nHibernate. It has been worked on by several developers over the last few years so we assume somewhere a mapping was set-up incorrectly and that nHibernate believes it should be deleting these records.
I used log4net to log all SQL generated by nHibernate from both our admin and front-end (in seperate files). Oddly enough it seems the front-end of our site occasionally generates the DELETES for the then missing records. It's odd because although the front-end and back-end share the same data model the front-end shouldn't have any write/update functionality. We were sure it was a bug in admin where all the CRUD is. Yet there it is in the logs... a batch of DELETES.
I would like to get more information about where in the stack these SQL statements are being generated from. If I could somehow get a small stack trace before every nHibernate transaction that would be great. So far my log4net settings look like this:
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender,log4net" >
<param name="File" value="nHibernate.txt" />
<param name="AppendToFile" value="true" />
<param name="DatePattern" value="yyyy.MM.dd" />
<layout type="log4net.Layout.PatternLayout,log4net">
<conversionPattern value="%d %p %m%n" />
</layout>
</appender>
<logger name="NHibernate.SQL" additivity="false">
<level value="DEBUG" />
<appender-ref ref="RollingFile" />
</logger>
Maybe I just need to log the two things separately and compare the times myself? I'm just looking for a suggestion.
Thanks!