I have read http://logging.apache.org/log4net/release/config-examples.html and understand that we can store logs in SQL Server database with following table definition. But my scenario is different. I have an existing table (ExceptionLog) used by many applications. It’s columns are somewhat different.
Is it possible to configure log4Net to use this existing table? How can we do that?
Log4Net Table detention:
CREATE TABLE [dbo].[Log] (
[Id] [int] IDENTITY (1, 1) NOT NULL,
[Date] [datetime] NOT NULL,
[Thread] [varchar] (255) NOT NULL,
[Level] [varchar] (50) NOT NULL,
[Logger] [varchar] (255) NOT NULL,
[Message] [varchar] (4000) NOT NULL,
[Exception] [varchar] (2000) NULL
)
Existing Table:
CREATE TABLE [dbo].[ ExceptionLog] (
[ExceptionLogId] [int] NOT NULL,
[Date] [datetime] NOT NULL,
[Exception] [varchar] (2000) NOT NULL,
[IsInternalApp] [varchar] (1) NOT NULL,
[Operation] [varchar] (1000) NOT NULL
)
You may be looking for the .AdoNetAppender that allows to log into a database table.
Also, if this is not what you want, have a look at the overview of all appenders.
Finally, you could implement your own. Here are examples: How to store log in database using log4net or Writing An Appender For log4net