logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicko Cadell" <ni...@neoworks.com>
Subject RE: Transactions and AdoNetAppender
Date Fri, 02 Sep 2005 16:54:08 GMT
I think that sample FastDbAppender should probably be changed to use the
ServicedComponent base class, and isolate itself from any COM+
transactions. 

It will be more difficult to add this to the AdoNetAppender as it
extends BufferingAppenderSkeleton and that extends AppenderSkeleton.
They could be reimplemented but that would be a breaking change :(. So
realistically we will just have to document the fact that the
AdoNetAppender will be auto-enlisted into a COM+ transaction, and
therefore should not be used.

Nicko

> -----Original Message-----
> From: Michael S. Collier 
> [mailto:michael.collier@centricconsulting.com] 
> Sent: 02 September 2005 16:59
> To: 'Log4NET User'
> Subject: RE: Transactions and AdoNetAppender
> 
> I was able to take the FastDbAppender and modify the schema 
> to match my table.  When I used that, it seemed to fix the 
> SqlException I mentioned originally.  However, the log 
> messages were still being rolled back.  I understand that the 
> COM+ transaction was responsible for the roll back.
> What I don't understand yet is why the AdoNetAppender 
> generates that SqlException, and the FastDbAppender does not. 
>  I'll try to look into this more.
> 
> Also, I wrote a version of FastDbAppender that derives from 
> ServicedComponent.  I marked this class with the 
> [Transaction(TransactionOption.NotSupported)] attribute.  
> This seems to work as expected.  Meaning, log messages 
> generated by this appender implementation are not part of the 
> COM+ transaction, and thus not being rolled back.
> 
> So far this is working in my sample app.  I'll move it to my 
> real app shortly.
> 
> 
> Do you think the version of FastDbAppender that derives from 
> ServicedComponent would be something that the Log4Net 
> community as a whole would be interested in?
> 
> 
> Thanks,
> Mike
> 
> -----Original Message-----
> From: Nicko Cadell [mailto:nicko@neoworks.com]
> Sent: Thursday, September 01, 2005 4:44 PM
> To: Log4NET User
> Subject: RE: Transactions and AdoNetAppender
> 
> Mike,
> 
> The AdoNetAppender can be used to buffer events and write 
> them to the database in a batch. The UseTransactions property 
> only affects this batch write where optionally a transaction 
> can be created to ensure that the whole batch is written consistently.
> 
> Of course even when the AdoNetAppender does not create an 
> explicit transaction the SQL database will create an auto 
> commit transaction for each statement. If you are creating a 
> COM+ distributed transaction then the SQL driver may be auto 
> enlisting the AdoNetAppender commands into your transaction. 
> That appears to be the behaviour you are describing.
> I'm not sure what the scope of the COM+ transaction is. It 
> may be possible to escape it by doing asynchronous logging 
> using a thread pool thread, i.e. using something like the 
> AsyncAppender in front of the AdoNetAppender to push the 
> logging onto a separate thread.
> 
> The AsyncAppender is in the same place as the FastDbAppender
> 
> http://tinyurl.com/7unou
> 
> http://cvs.apache.org/viewcvs.cgi/logging-log4net/examples/net
> /1.0/Appen
> ders/SampleAppendersApp/cs/src/Appender/
> 
> Cheers,
> Nicko
> 
> > -----Original Message-----
> > From: Michael S. Collier
> > [mailto:michael.collier@centricconsulting.com]
> > Sent: 01 September 2005 20:23
> > To: 'Log4NET User'
> > Subject: RE: Transactions and AdoNetAppender
> > 
> > I'm looking at the FastDbAppender now, and I'm not sure I 
> understand 
> > what makes it different from the AdoNetAppender.
> > I see that it doesn't derive from AppenderSkeleton, and uses a 
> > hard-coded table structure.  But how does that not use 
> transactions?  
> > I thought by setting the UseTransactions property to 'false', the 
> > AdoNetAppender wouldn't use transactions.  Is that not 
> necessarily the 
> > case?
> > 
> > Thanks,
> > Mike
> > 
> > -----Original Message-----
> > From: Ron Grabowski [mailto:rongrabowski@yahoo.com]
> > Sent: Thursday, September 01, 2005 2:53 PM
> > To: Log4NET User
> > Subject: RE: Transactions and AdoNetAppender
> > 
> > You could host the file on a friend's website, your 
> company's website 
> > for a few days, or use a free service like this:
> > 
> >  http://www.yousendit.com/
> > 
> > Is the class really that large that it needs to be a .ZIP file? Can 
> > you condense your working example down into one or two small text 
> > files and attach those?
> > 
> > The FastDbAppender appender doesn't use transactions:
> > 
> > http://tinyurl.com/7unou
> > http://cvs.apache.org/viewcvs.cgi/logging-log4net/examples/net
> > /1.0/Appenders
> > /SampleAppendersApp/cs/src/Appender/
> > 
> > --- "Michael S. Collier" 
> > <michael.collier@centricconsulting.com> wrote:
> > 
> > > First, thanks for the help.
> > > 
> > > I'm not sure I totally understand what you're telling me.
> > > 
> > > I've worked up a sample application that basically does what I'm 
> > > trying to do in my real application.  I would post it, but
> > apparently
> > > the mailing list doesn't let me post ZIP files.  Any ideas
> > how to get
> > > around this?
> > > 
> > > Thanks,
> > > Mike
> > > 
> > > 
> > > -----Original Message-----
> > > From: Aaron Morton [mailto:log4net@the-mortons.org]
> > > Sent: Thursday, September 01, 2005 9:52 AM
> > > To: Log4NET User
> > > Subject: Re: Transactions and AdoNetAppender
> > > 
> > > Michael.
> > > 
> > > Could it be that another part of your app is witting a 
> log message 
> > > before MethodA ? Or that log4net is been initialized by a 
> component 
> > > that has a different transactions attribute value.
> > > 
> > > If so this could be the reason the thin wrapper did not
> > work. As the
> > > ADO appender caches it connection for a while, perhaps the
> > connection
> > > is been associated with the Transactions property of the
> > object that
> > > caused it to be created. This is just a wild theory, you
> > could test it
> > > with your thin wrapper class making sure log4net is not
> > initialised or
> > > called by another part of the app.
> > > 
> > > let me know if this makes sense. If your still having
> > problems let me
> > > 
> > > know, if you have some sample code that would be handy.
> > > 
> > > thanks
> > > aaron
> > > 
> > > ---
> > > I'm having a problem using AdoNetAppender without 
> transactions.  I 
> > > have a .NET class that derives from ServicedComponent.
> > This class is
> > > used as a Queued Component.  Everything about the Queued 
> Component 
> > > seems to be working as expected.  The class is marked with the 
> > > [Transaction(TransactionOption.Required)] attribute.  In
> > the method,
> > > let's call it MethodA, some logic is performed and data is then 
> > > written to the database.  If there is an exception, the
> > exception is
> > > caught and Log4Net is used to log the exception.  The 
> AutoComplete 
> > > attribute is set on MethodA to force a rollback.  Log4Net is 
> > > configured to write to a database via the AdoNetAppender 
> and to the 
> > > local file system.  My problem is that the exception data
> > is not being
> > > written to the database.  I can see the exception data in
> > my log file
> > > though.
> > > 
> > > 
> > > Using DebugView I see the following exception from Log4Net
> > when I try
> > > to
> > > log
> > > the exception data:
> > > 
> > > 
> > > log4net:ERROR [AdoNetAppender] Failed in DoAppend
> > > 
> > > System.Data.SqlClient.SqlException: Distributed transaction 
> > > completed.
> > > Either enlist this session in a new transaction or the NULL 
> > > transaction.
> > > 
> > >    at 
> System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
> > > cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
> > > 
> > >    at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
> > > 
> > >    at log4net.Appender.AdoNetAppender.SendBuffer(IDbTransaction
> > > dbTran,
> > > LoggingEvent[] events)
> > > 
> > >    at log4net.Appender.AdoNetAppender.SendBuffer(LoggingEvent[]
> > > events)
> > > 
> > >    at 
> log4net.Appender.BufferingAppenderSkeleton.Append(LoggingEvent
> > > loggingEvent)
> > > 
> > >    at log4net.Appender.AppenderSkeleton.DoAppend(LoggingEvent
> > > loggingEvent)
> > > 
> > > 
> > > I have set the UseTransactions property to 'false' on the 
> > > AdoNetAppender.
> > > That didn't seem to help.  I have also tried making a 
> thin wrapper 
> > > class around Log4Net, and marking that class with 
> > > [Transaction(TransactionOption.NotSupported)].  That didn't help 
> > > either.
> > > 
> > > I'm really confused as to why there appears to be a 
> transaction when 
> > > I'm using Log4Net.  To prove this I added another method 
> to my thin 
> > > wrapper class that executes the same stored procedure I've 
> > > configured the AdoNetAppender to use.  Doing that worked. 
>  So, I'm 
> > > pretty
> > sure that
> > > somehow
> > > Log4Net is still using a transaction.
> > > 
> > > Any help on how to solve this problem would be greatly 
> appreciated.
> > > 
> > > 
> > > I'm running .NET 1.1 on Windows XP Pro SP2.
> > > 
> > > 
> > 
> > 
> 
> 

Mime
View raw message