logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Green" <James.Gr...@occam-dm.com>
Subject RE: Using AdoNetAppender
Date Mon, 15 Jun 2009 16:04:16 GMT
I think I'm going to have to try the config file method first.
 
I'm wrapping log4net and I don't want to cause every consuming component
to require loads of config information in it just for logging purposes.
 
Everything else is a sinch to configure in code, save for this appender
... *sigh* ...
 
Cheers,
 
James.

  _____  

From: codingvista@googlemail.com [mailto:codingvista@googlemail.com] On
Behalf Of Wayne Douglas
Sent: 15 June 2009 16:57
To: Log4NET User
Subject: Re: Using AdoNetAppender


AppConfig is much simpler - you should start with that then convert to
this if you need to - not sure why you'd need to tho?


On Mon, Jun 15, 2009 at 4:31 PM, James Green <James.Green@occam-dm.com>
wrote:


	I may have to try that.  Currently it just fails with an "Oject
	reference not set to an instance of an object."
	
	Thanks,
	
	James.
	

	-----Original Message-----
	From: Matt Lund [mailto:mlund@control4.com]
	Sent: 15 June 2009 16:28
	To: Log4NET User
	Subject: RE: Using AdoNetAppender
	
	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;
	_sqlDatabaseAppender.AddParameter(logDate);
	AdoNetAppenderParameter logThread = new
AdoNetAppenderParameter();
	logThread.ParameterName = "@thread";
	logThread.Size = 255;
	logThread.DbType = System.Data.DbType.String;
	_sqlDatabaseAppender.AddParameter(logThread);
	AdoNetAppenderParameter logLevel = new
AdoNetAppenderParameter();
	logLevel.ParameterName = "@log_level";
	logLevel.Size = 50;
	logLevel.DbType = System.Data.DbType.String;
	_sqlDatabaseAppender.AddParameter(logLevel);
	AdoNetAppenderParameter logLogger = new
AdoNetAppenderParameter();
	logLogger.ParameterName = "@logger";
	logLogger.Size = 255;
	logLogger.DbType = System.Data.DbType.String;
	_sqlDatabaseAppender.AddParameter(logLogger);
	AdoNetAppenderParameter logMessage = new
AdoNetAppenderParameter();
	logMessage.ParameterName = "@message";
	logMessage.Size = 4000;
	logMessage.DbType = System.Data.DbType.String;
	_sqlDatabaseAppender.AddParameter(logMessage);
	AdoNetAppenderParameter logException = new
AdoNetAppenderParameter();
	logException.ParameterName = "@exception";
	logException.Size = 2000;
	logException.DbType = System.Data.DbType.String;
	_sqlDatabaseAppender.AddParameter(logException);
	_sqlDatabaseAppender.ActivateOptions();
	
	BasicConfigurator.Configure(_sqlDatabaseAppender);
	}
	
	Any help would be great.
	
	James.
	
	
	
	scanned by MessageLabs [www.messagelabs.com]
	
	
	




-- 
Cheers,

w://

scanned by MessageLabs [www.messagelabs.com]


Mime
View raw message