Hi,
Guys I am in soup.
I am trying to use log to database using adoNetAppender. I am working on
visual studio 2005 with vb.net.
nothing is showing in my database. Also I m not getting any error messages.
I am not sure if it is some version problem.
my appender is
<log4net>
<appender name="ADONetAppender"
type="log4net.Appender.ADONetAppender">
<bufferSize value="1" />
<connectionType
value="System.Data.SqlClient.SqlConnection ,
System.Data.SqlServer, Version=3.0.3600.0, Culture=neutral,
PublicKeyToken=3be235df1c8d2ad3" />
<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" >
<conversionPattern
value="%date{yyyy'/'MM'/'dd HH':'mm':'ss'.'fff}" />
</layout>
</parameter>
<parameter>
<parameterName value="@thread" />
<dbType value="String" />
<size value="255" />
<layout
type="log4net.Layout.PatternLayout">
<conversionPattern
value="%thread" />
</layout>
</parameter>
<parameter>
<parameterName value="@log_level" />
<dbType value="String" />
<size value="50" />
<layout
type="log4net.Layout.PatternLayout">
<conversionPattern
value="%level" />
</layout>
</parameter>
<parameter>
<parameterName value="@logger" />
<dbType value="String" />
<size value="255" />
<layout
type="log4net.Layout.PatternLayout">
<conversionPattern
value="%logger" />
</layout>
</parameter>
<parameter>
<parameterName value="@message" />
<dbType value="String" />
<size value="4000" />
<layout
type="log4net.Layout.PatternLayout">
<conversionPattern
value="%message" />
</layout>
</parameter>
<parameter>
<parameterName value="@exception" />
<dbType value="String" />
<size value="2000" />
<layout
type="log4net.Layout.ExceptionLayout" />
</parameter>
</appender>
<appender name="RollingLogFileAppender"
type="log4net.Appender.RollingFileAppender">
<file value="TestLog.txt"/>
<appendToFile value="true"/>
<rollingStyle value="Size"/>
<maxSizeRollBackups value="10"/>
<maximumFileSize value="12KB"/>
<staticLogFileName value="true"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms
%-22.22c{1} %-18.18M - %m%n"/>
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="ADONetAppender" />
</root>
<logger name="myjsk">
<appender-ref ref="ADONetAppender" />
</logger>
also my database is <!--CREATE TABLE [dbo].[Log] ( [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)-->
In application start of my global.asax :
Try
log4net.Config.XmlConfigurator.Configure()
Dim hier As log4net.Repository.Hierarchy.Hierarchy =
TryCast(log4net.LogManager.GetRepository(),
log4net.Repository.Hierarchy.Hierarchy)
If hier IsNot Nothing Then
Dim adoAppender As log4net.Appender.AdoNetAppender =
DirectCast(hier.GetLogger("myjsk",
hier.LoggerFactory).GetAppender("ADONetAppender"),
log4net.Appender.AdoNetAppender)
If adoAppender IsNot Nothing Then
adoAppender.ConnectionString =
System.Configuration.ConfigurationManager.AppSettings("conn")
''System.Configuration.ConfigurationSettings.AppSettings("Conn")
adoAppender.ActivateOptions()
End If
End If
Catch nfe As NullReferenceException
Throw New NullReferenceException("log4net configuration could
not be completed. " & Chr(10) & "Do you have your app.config set up
properly?", nfe)
End Try
On my which action, data will move into database?
any suggestions?
Thanks
Sarika
Chris Jerdonek-2 wrote:
>
> Hi, we've been using log4net for a few months now, and I've been on this
> list for about the same. I have a design question.
>
> What would be the "correct" way to do the following?
>
> We'd like to log to a database using the AdoNetAppender. From our code,
> when we call things like log.Debug, log.Info, log.Warn, etc. we'd like to
> be able to pass not just a "message" but also things like a local message
> code, message details, etc and then have those show up in separate columns
> in the database. Also, the list of things we pass may change over time.
>
> To implement this, it seems natural to store these additional values in
> ThreadContext.Properties, and then access them in the Web.config via (for
> example) %property{msgcode}.
>
> Would we, for example, want to wrap the LogManager class with our own
> class whose GetLogger method returns an ILog with overloaded Debug, Info,
> Warn, etc. methods?
>
> One problem with this approach is that if every one of these methods had
> message code, message details, etc in the signature, then it would
> probably be hard to maintain: there may be lots of overloads, and changing
> the signatures over time would probably break things.
>
> Another possibility is to have the custom ILog object expose setters for
> things like message code, message details, etc (which would wrap writes to
> ThreadContext.Properties); but this would make calling log.Info, log.Warn,
> etc. a bit more verbose -- you would have to set everything prior to
> calling the log method instead of just including them as parameters in the
> method call. Also, you would probably want to delete those particular
> ThreadContext.Properties values so they don't persist to the next log
> message.
>
> Any thoughts?
>
> Okay, thanks,
> --Chris
>
>
>
> --
> Chris Jerdonek
> Software Developer
> P: (415) 357-3618 Ext. 1357
> Granicus, Inc.
>
>
>
--
View this message in context:
http://www.nabble.com/logging-additional-message-specific-data-with-AdoNetAppender-tp17139552p17185843.html
Sent from the Log4net - Users mailing list archive at Nabble.com.