Search code examples
log4netadonetappender

Using sps for inserting log information in log4net


I'm using ADO.NET Appender of log4net for logging errors and other info. to database. I see usually the connection string, sql query, parameters all are specified in the configuration.

Is it possible to do that through code? I've a database component in my application and all the interactions with database should be taken care by itself. Whenever I try to log details using log4net I want to call the log method from the database component which will call an SP to record the log information into database. How can I achieve this using log4net?


Solution

  • If I understand you correctly you do not want log4net to call the stored procedure directly. In that case you need to implement your own appender. I suggest that you download the log4net source code and look at the existing appenders.

    I would assume that in this case you do not even need to configure the appender in code. It is however possible to do so. If you google you will find many examples like this one: How to configure log4net programmatically from scratch (no config)