Reputation: 5651
I use log4net in my project as well as NHibernate. Each logged piece of information is stored as an instance of MyLog
object, which is already an NHibernate entity with its mapping, table etc. I also need to load the logs from the database and display it to a user, that is why NHibernate approach seems to be quite handy.
It is not difficult to setup logging into a database using the AdoNetAppender
as described here:
How to use Log4Net utility for logging into database using c#
However, I am wondering why would I have to explicitely configure all the column-property mapping in my config file:
<commandText value="INSERT INTO log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
<parameter>
<parameterName value="@log_date"/>
<dbType value="DateTime"/>
<layout type="log4net.Layout.RawTimeStampLayout"/>
</parameter>
...
although I have already done it in my fluent API mapping!
public LogRecordMap () {
Table("log");
Id(x => x.ID)
.Column("id")
.GeneratedBy.Native();
Map(x => x.ObjectID)
.Column("objectid")
.Not.Nullable()
...
I find it duplicate, because I have to maintain both the fluent mapping and the AdoNetAppender
configuration. Is there any "NHibernateAppender
" I could provide with my mapping class instead of the direct SQL command with all its params as I have to provide the AdoNetAppender
?
Upvotes: 0
Views: 426
Reputation: 27934
I would recommend to keep your logging and application separate. Logging should not depend on your application in the form of a mapping. If you break something in your application, logging should keep working. Having two mappings to you log table looks double. But how often will they change? If you only want to use nhibernate for accessing the db, you can write a custom appender to do so.
Upvotes: 1