logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matt Lund" <ml...@control4.com>
Subject RE: Using AdoNetAppender
Date Mon, 15 Jun 2009 15:27:32 GMT
Have you already gotten AdoNetAppender to work from a app.config /
web.config first?  If not, I'd suggest getting that to work first.  You
may learn something in that process and it'll spark a realization of
what you're missing in the from-code approach?

-----Original Message-----
From: James Green [mailto:James.Green@occam-dm.com] 
Sent: Monday, June 15, 2009 9:26 AM
To: Log4NET User
Subject: Using AdoNetAppender

Hi All,
I've spent about 4 hours today trying to get this working and have
totally failed so far.
I can't even really find much info on how to configure this purely in
Code.  In fact there is precious little I can find on the net in fact.
Here is the code I'm using the set up the AdoNetAppender in my app:
public static void ConfigureDatabaseAppender(string connString)
PatternLayout layout = GetDefaultLayout();
_sqlDatabaseAppender = new AdoNetAppender();
_sqlDatabaseAppender.Layout = layout;
_sqlDatabaseAppender.UseTransactions = false;
_sqlDatabaseAppender.BufferSize = 1;
_sqlDatabaseAppender.CommandType = System.Data.CommandType.Text;
_sqlDatabaseAppender.ConnectionString = connString;
_sqlDatabaseAppender.CommandText = "INSERT INTO Log
([Date],[Level],[Thread],[Logger],[Message],[Exception]) VALUES
(@log_date, @log_level, @thread, @logger, @message, @exception)";
AdoNetAppenderParameter logDate = new AdoNetAppenderParameter();
RawTimeStampLayout dateLayout = new RawTimeStampLayout();
logDate.ParameterName = "@log_date";
logDate.Layout = dateLayout;
logDate.DbType = System.Data.DbType.DateTime;
AdoNetAppenderParameter logThread = new AdoNetAppenderParameter();
logThread.ParameterName = "@thread";
logThread.Size = 255;
logThread.DbType = System.Data.DbType.String;
AdoNetAppenderParameter logLevel = new AdoNetAppenderParameter();
logLevel.ParameterName = "@log_level";
logLevel.Size = 50;
logLevel.DbType = System.Data.DbType.String;
AdoNetAppenderParameter logLogger = new AdoNetAppenderParameter();
logLogger.ParameterName = "@logger";
logLogger.Size = 255;
logLogger.DbType = System.Data.DbType.String;
AdoNetAppenderParameter logMessage = new AdoNetAppenderParameter();
logMessage.ParameterName = "@message";
logMessage.Size = 4000;
logMessage.DbType = System.Data.DbType.String;
AdoNetAppenderParameter logException = new AdoNetAppenderParameter();
logException.ParameterName = "@exception";
logException.Size = 2000;
logException.DbType = System.Data.DbType.String;

Any help would be great.


View raw message