You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Brian Elcock <br...@gmail.com> on 2006/08/18 00:59:45 UTC

Log4Net and logging SQL Statements

Hello All.

I'm struggling with getting logging setup to log all prepared/executed
SQL statements. I am using .NET 1.1, Log4Net 1.2.9.0,
IBatisNet.DataMapper 1.3.0.0. I can write to the log just fine from
within the application when I'm testing, but I can't get iBatis to log
the SQL statements. I've looked at the developer guide, and it seems
pretty straightforward, but I'm clearly missing something somewhere.

My solution is broken up into 3 separate projects:

1. Domain
2. Model (where all the iBatis interaction lives)
3. Web

Any help would be greatly appreciated.

Here are the relevant parts of my configuration:

	<configSections>
		<sectionGroup name="iBATIS">
			<section name="logging"
type="IBatisNet.Common.Logging.ConfigurationSectionHandler,
IBatisNet.Common" />
		</sectionGroup>
		<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
	</configSections>
	
	<iBATIS>
		<logging>
			<logFactoryAdapter
type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA,
IBatisNet.Common.Logging.Log4Net">
				<arg key="configType" value="file" />
				<arg key="configFile" value="Log4Net.config" />
			</logFactoryAdapter>
		</logging>
	</iBATIS>

	<log4net>

		<!-- Define some output appenders -->
		<appender name="RollingLogFileAppender"
type="log4net.Appender.RollingFileAppender">
			<file value="log.log" />
			<appendToFile value="true" />
			<maximumFileSize value="5MB" />
			<maxSizeRollBackups value="-1" />
			<layout type="log4net.Layout.PatternLayout">
				<conversionPattern value="%5level [%date] %-40.40logger{2}
%message%newline" />
			</layout>
		</appender>
		
		<!-- OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL -->
		<!-- Set root logger level to ERROR and its appenders -->
		<root>
			<level value="ALL" />
			<appender-ref ref="RollingLogFileAppender" />
		</root>
		
        <logger name="IBatisNet">
			<appender-ref ref="RollingLogFileAppender" />
        </logger>

		<logger name="IBatisNet.DataMapper.Commands.DefaultPreparedCommand">
			<level value="ALL" />
		</logger>
		
	</log4net>

Re: Log4Net and logging SQL Statements

Posted by Brian Elcock <br...@gmail.com>.
I just wanted to follow up on this, in case anyone else out there was
struggling with the same issue. I sort of gave up because it *seemed*
like I was doing everything right and that it should be working. But,
of course, it wasn't. Then I got an email from one of the many great
users on this list who suggested that I might have been missing
something incredibly simple and (now, at least) very obvious. I was
missing a reference to IBatisNet.Common.Logging.Log4Net. So I added
the reference and everything was golden.

A big thank you to Nicholas Piasecki.

Brian

On 8/25/06, Brian Elcock <br...@gmail.com> wrote:
> Mike.
>
> Thanks for your reply. I'm hesitant to introduce the newer version of
> log4net because IBatis itself uses 1.2.9. It's not as simple as just
> replacing the DLL, unfortunately. Or, if it is, let me know if I need
> to change anything w/ IBatis itself.
>
> I tried including an appender like you did below, but that didn't do
> anything for me.
>
> In addition to what I wrote before, let me include that this is how
> I'm configuring Log4Net in my Assembly file:
>
> [assembly: log4net.Config.XmlConfiguratorAttribute(ConfigFile="Log4Net.config",Watch=true)]
>
> Again, my Log4Net.config file contains, simply, the following:
>
>         <log4net>
>
>                 <!-- Define some output appenders -->
>                 <appender name="RollingLogFileAppender"
> type="log4net.Appender.RollingFileAppender">
>                         <file value="log.log" />
>                         <appendToFile value="true" />
>                         <maximumFileSize value="5MB" />
>                         <maxSizeRollBackups value="-1" />
>                         <layout type="log4net.Layout.PatternLayout">
>                                 <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
>                         </layout>
>                 </appender>
>
>                 <!-- OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL -->
>                 <!-- Set root logger level to ERROR and its appenders -->
>                 <root>
>                         <level value="ALL" />
>                         <appender-ref ref="RollingLogFileAppender" />
>                 </root>
>
>                 <logger name="IBatisNet">
>                         <appender-ref ref="RollingLogFileAppender" />
>                 </logger>
>
>         </log4net>
>
> And my web.config file contains:
>
>         <configSections>
>                 <sectionGroup name="iBATIS">
>                         <section name="logging"
> type="IBatisNet.Common.Logging.ConfigurationSectionHandler,
> IBatisNet.Common" />
>                 </sectionGroup>
>         </configSections>
>
>         <iBATIS>
>                 <logging>
>                         <logFactoryAdapter
> type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA,
> IBatisNet.Common.Logging.Log4Net">
>                                 <arg key="configType" value="external" />
>                         </logFactoryAdapter>
>                 </logging>
>         </iBATIS>
>
> Yet nothing happens w/ the IBatis information being logged. Using
> log4net directly works fine. IBatis doesn't seem to be able to get a
> hold of it. Can anyone suggest anything else? Or is there a different
> way you would suggest setting things up? I noticed another question
> regarding this, so hopefully an answer will help many! I know that
> this will help me further my quest to get IBatis used more in my
> organization.
>
> Thanks again.
>
> Brian
>

Re: Log4Net and logging SQL Statements

Posted by Brian Elcock <br...@gmail.com>.
Mike.

Thanks for your reply. I'm hesitant to introduce the newer version of
log4net because IBatis itself uses 1.2.9. It's not as simple as just
replacing the DLL, unfortunately. Or, if it is, let me know if I need
to change anything w/ IBatis itself.

I tried including an appender like you did below, but that didn't do
anything for me.

In addition to what I wrote before, let me include that this is how
I'm configuring Log4Net in my Assembly file:

[assembly: log4net.Config.XmlConfiguratorAttribute(ConfigFile="Log4Net.config",Watch=true)]

Again, my Log4Net.config file contains, simply, the following:

	<log4net>

		<!-- Define some output appenders -->
		<appender name="RollingLogFileAppender"
type="log4net.Appender.RollingFileAppender">
			<file value="log.log" />
			<appendToFile value="true" />
			<maximumFileSize value="5MB" />
			<maxSizeRollBackups value="-1" />
			<layout type="log4net.Layout.PatternLayout">
				<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
			</layout>
		</appender>
		
		<!-- OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL -->
		<!-- Set root logger level to ERROR and its appenders -->
		<root>
			<level value="ALL" />
			<appender-ref ref="RollingLogFileAppender" />
		</root>
		
		<logger name="IBatisNet">
			<appender-ref ref="RollingLogFileAppender" />
		</logger>
				
	</log4net>

And my web.config file contains:

	<configSections>
		<sectionGroup name="iBATIS">
			<section name="logging"
type="IBatisNet.Common.Logging.ConfigurationSectionHandler,
IBatisNet.Common" />
		</sectionGroup>
	</configSections>
	
	<iBATIS>
		<logging>
			<logFactoryAdapter
type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA,
IBatisNet.Common.Logging.Log4Net">
				<arg key="configType" value="external" />
			</logFactoryAdapter>
		</logging>
	</iBATIS>

Yet nothing happens w/ the IBatis information being logged. Using
log4net directly works fine. IBatis doesn't seem to be able to get a
hold of it. Can anyone suggest anything else? Or is there a different
way you would suggest setting things up? I noticed another question
regarding this, so hopefully an answer will help many! I know that
this will help me further my quest to get IBatis used more in my
organization.

Thanks again.

Brian

Re: Log4Net and logging SQL Statements

Posted by Michael Schall <mi...@gmail.com>.
I think you have to include an appender in your logger tag.

When using log4net 1.2.9.0 and iBatis, this is how we got it to write
to the file.

<logger name="IBatisNet">
    <appender-ref ref="RollingLogFileAppender" />
</logger>

This rule will log everything from the IBatisNet namespace to the rolling file.

This is a workaround, because as I understand it your root tag should
take care of it.  However you need the extra rule is needed for some
reason.

If you upgrade to log4net 1.2.10.0, you no longer need the extra rule.
 We were actually double logging everything from IBATIS for awhile.

Hope this helps.
Mike

Re: Log4Net and logging SQL Statements

Posted by Brian Elcock <br...@gmail.com>.
Sorry to keep on you all about this. I just can't seem to figure it
out. Here's what I've got in my web.config file (the relevant parts):

	<configSections>
		<sectionGroup name="iBATIS">
			<section name="logging"
type="IBatisNet.Common.Logging.ConfigurationSectionHandler,
IBatisNet.Common" />
		</sectionGroup>
	</configSections>
	
	<iBATIS>
		<logging>
			<logFactoryAdapter
type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA,
IBatisNet.Common.Logging.Log4Net">
				<arg key="configType" value="external" />
			</logFactoryAdapter>
		</logging>
	</iBATIS>

>From what I understand, the "external" value in the configType tells
IBatis that it will not need to configure the logger, as it's
configured externally. I have Log4Net configured and working just fine
from within my application. I am using a separate Log4Net.config file
for all of that configuration. Here are some snippets from that file:

	<log4net>

		<!-- Define some output appenders -->
		<appender name="RollingLogFileAppender"
type="log4net.Appender.RollingFileAppender">
			<file value="log.log" />
			<appendToFile value="true" />
			<maximumFileSize value="5MB" />
			<maxSizeRollBackups value="-1" />
			<layout type="log4net.Layout.PatternLayout">
				<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
			</layout>
		</appender>
		
		<!-- OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL -->
		<!-- Set root logger level to ERROR and its appenders -->
		<root>
			<level value="ALL" />
			<appender-ref ref="RollingLogFileAppender" />
		</root>
		
		<logger name="IBatisNet.DataMapper.Commands.DefaultPreparedCommand">
			<level value="ALL" />
		</logger>
		
		<logger name="IBatisNet.DataMapper.Configuration.Cache.CacheModel">
			<level value="ALL" />
		</logger>
		<logger name="IBatisNet.DataMapper.LazyLoadList">
			<level value="ALL" />
		</logger>
		<logger name="IBatisNet.DataMapper.SqlMapSession">
			<level value="ALL" />
		</logger>
		<logger name="IBatisNet.Common.Transaction.TransactionScope">
			<level value="ALL" />
		</logger>
		<logger name="IBatisNet.DataAccess.DaoSession">
			<level value="ALL" />
		</logger>
		<logger name="IBatisNet.DataAccess.Configuration.DaoProxy">
			<level value="ALL" />
		</logger>
		<logger name="IBatisNet.DataMapper.Configuration.Statements.PreparedStatementFactory">
			<level value="ALL" />
		</logger>
		<logger name="IBatisNet.DataMapper.Commands.IPreparedCommand">
			<level value="ALL" />
		</logger>
				
	</log4net>

Yet nothing from IBatis is logged. I've played with the level values
and what not, but nothing ever changes. Is there something I'm
missing? Thanks for any help.

Brian

On 8/17/06, Brian Elcock <br...@gmail.com> wrote:
> OK. Thanks. That makes sense. I've updated my configuration to include
> the external value. Now in my logger config file, I've got this:
>
>                 <logger name="IBatisNet.DataMapper.Commands.DefaultPreparedCommand">
>                         <level value="ALL" />
>                 </logger>
>
> The developer guide says:
>
> To log all Prepared SQL command text, enable the logger for
> IBatisNet.DataMapper.Configuration.Statements.DefaultPreparedCommand.
> This will display the statement, parameters, and parameter types used
> by the DataMapper.
>
> Do I need to do something other than the above line to make this happen?
>
> Thanks for your help.
>
> On 8/17/06, Ron Grabowski <ro...@yahoo.com> wrote:
> > With your current configuration, you're telling your application to
> > look for the log4net configuration in the App/Web.config and for
> > IBatisNet to re-configure log4net from the Log4net.config file. I
> > usually configure log4net from my application and tell IBatisNet to
> > attach itself to that configuration:
> >
> >  <iBATIS>
> >   <logging>
> >    <logFactoryAdapter
> > type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA,
> > IBatisNet.Common.Logging.Log4Net">
> >     <arg key="configType" value="external" />
> >    </logFactoryAdapter>
> >   </logging>
> >  </iBATIS>
> >
> > The configType value extenral tells IBatisNet that log4net has already
> > been configured.
> >
> > --- Brian Elcock <br...@gmail.com> wrote:
> >
> > > Hello All.
> > >
> > > I'm struggling with getting logging setup to log all
> > > prepared/executed
> > > SQL statements. I am using .NET 1.1, Log4Net 1.2.9.0,
> > > IBatisNet.DataMapper 1.3.0.0. I can write to the log just fine from
> > > within the application when I'm testing, but I can't get iBatis to
> > > log
> > > the SQL statements. I've looked at the developer guide, and it seems
> > > pretty straightforward, but I'm clearly missing something somewhere.
> > >
> > > My solution is broken up into 3 separate projects:
> > >
> > > 1. Domain
> > > 2. Model (where all the iBatis interaction lives)
> > > 3. Web
> > >
> > > Any help would be greatly appreciated.
> > >
> > > Here are the relevant parts of my configuration:
> > >
> > >       <configSections>
> > >               <sectionGroup name="iBATIS">
> > >                       <section name="logging"
> > > type="IBatisNet.Common.Logging.ConfigurationSectionHandler,
> > > IBatisNet.Common" />
> > >               </sectionGroup>
> > >               <section name="log4net"
> > > type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
> > >       </configSections>
> > >
> > >       <iBATIS>
> > >               <logging>
> > >                       <logFactoryAdapter
> > > type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA,
> > > IBatisNet.Common.Logging.Log4Net">
> > >                               <arg key="configType" value="file" />
> > >                               <arg key="configFile" value="Log4Net.config" />
> > >                       </logFactoryAdapter>
> > >               </logging>
> > >       </iBATIS>
> > >
> > >       <log4net>
> > >
> > >               <!-- Define some output appenders -->
> > >               <appender name="RollingLogFileAppender"
> > > type="log4net.Appender.RollingFileAppender">
> > >                       <file value="log.log" />
> > >                       <appendToFile value="true" />
> > >                       <maximumFileSize value="5MB" />
> > >                       <maxSizeRollBackups value="-1" />
> > >                       <layout type="log4net.Layout.PatternLayout">
> > >                               <conversionPattern value="%5level [%date] %-40.40logger{2}
> > > %message%newline" />
> > >                       </layout>
> > >               </appender>
> > >
> > >               <!-- OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL -->
> > >               <!-- Set root logger level to ERROR and its appenders -->
> > >               <root>
> > >                       <level value="ALL" />
> > >                       <appender-ref ref="RollingLogFileAppender" />
> > >               </root>
> > >
> > >         <logger name="IBatisNet">
> > >                       <appender-ref ref="RollingLogFileAppender" />
> > >         </logger>
> > >
> > >               <logger
> > > name="IBatisNet.DataMapper.Commands.DefaultPreparedCommand">
> > >                       <level value="ALL" />
> > >               </logger>
> > >
> > >       </log4net>
> > >
> >
> >
>

Re: Log4Net and logging SQL Statements

Posted by Brian Elcock <br...@gmail.com>.
OK. Thanks. That makes sense. I've updated my configuration to include
the external value. Now in my logger config file, I've got this:

		<logger name="IBatisNet.DataMapper.Commands.DefaultPreparedCommand">
			<level value="ALL" />
		</logger>

The developer guide says:

To log all Prepared SQL command text, enable the logger for
IBatisNet.DataMapper.Configuration.Statements.DefaultPreparedCommand.
This will display the statement, parameters, and parameter types used
by the DataMapper.

Do I need to do something other than the above line to make this happen?

Thanks for your help.

On 8/17/06, Ron Grabowski <ro...@yahoo.com> wrote:
> With your current configuration, you're telling your application to
> look for the log4net configuration in the App/Web.config and for
> IBatisNet to re-configure log4net from the Log4net.config file. I
> usually configure log4net from my application and tell IBatisNet to
> attach itself to that configuration:
>
>  <iBATIS>
>   <logging>
>    <logFactoryAdapter
> type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA,
> IBatisNet.Common.Logging.Log4Net">
>     <arg key="configType" value="external" />
>    </logFactoryAdapter>
>   </logging>
>  </iBATIS>
>
> The configType value extenral tells IBatisNet that log4net has already
> been configured.
>
> --- Brian Elcock <br...@gmail.com> wrote:
>
> > Hello All.
> >
> > I'm struggling with getting logging setup to log all
> > prepared/executed
> > SQL statements. I am using .NET 1.1, Log4Net 1.2.9.0,
> > IBatisNet.DataMapper 1.3.0.0. I can write to the log just fine from
> > within the application when I'm testing, but I can't get iBatis to
> > log
> > the SQL statements. I've looked at the developer guide, and it seems
> > pretty straightforward, but I'm clearly missing something somewhere.
> >
> > My solution is broken up into 3 separate projects:
> >
> > 1. Domain
> > 2. Model (where all the iBatis interaction lives)
> > 3. Web
> >
> > Any help would be greatly appreciated.
> >
> > Here are the relevant parts of my configuration:
> >
> >       <configSections>
> >               <sectionGroup name="iBATIS">
> >                       <section name="logging"
> > type="IBatisNet.Common.Logging.ConfigurationSectionHandler,
> > IBatisNet.Common" />
> >               </sectionGroup>
> >               <section name="log4net"
> > type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
> >       </configSections>
> >
> >       <iBATIS>
> >               <logging>
> >                       <logFactoryAdapter
> > type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA,
> > IBatisNet.Common.Logging.Log4Net">
> >                               <arg key="configType" value="file" />
> >                               <arg key="configFile" value="Log4Net.config" />
> >                       </logFactoryAdapter>
> >               </logging>
> >       </iBATIS>
> >
> >       <log4net>
> >
> >               <!-- Define some output appenders -->
> >               <appender name="RollingLogFileAppender"
> > type="log4net.Appender.RollingFileAppender">
> >                       <file value="log.log" />
> >                       <appendToFile value="true" />
> >                       <maximumFileSize value="5MB" />
> >                       <maxSizeRollBackups value="-1" />
> >                       <layout type="log4net.Layout.PatternLayout">
> >                               <conversionPattern value="%5level [%date] %-40.40logger{2}
> > %message%newline" />
> >                       </layout>
> >               </appender>
> >
> >               <!-- OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL -->
> >               <!-- Set root logger level to ERROR and its appenders -->
> >               <root>
> >                       <level value="ALL" />
> >                       <appender-ref ref="RollingLogFileAppender" />
> >               </root>
> >
> >         <logger name="IBatisNet">
> >                       <appender-ref ref="RollingLogFileAppender" />
> >         </logger>
> >
> >               <logger
> > name="IBatisNet.DataMapper.Commands.DefaultPreparedCommand">
> >                       <level value="ALL" />
> >               </logger>
> >
> >       </log4net>
> >
>
>

Re: Log4Net and logging SQL Statements

Posted by Ron Grabowski <ro...@yahoo.com>.
With your current configuration, you're telling your application to
look for the log4net configuration in the App/Web.config and for
IBatisNet to re-configure log4net from the Log4net.config file. I
usually configure log4net from my application and tell IBatisNet to
attach itself to that configuration:

 <iBATIS>
  <logging>
   <logFactoryAdapter 
type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA,
IBatisNet.Common.Logging.Log4Net">
    <arg key="configType" value="external" />
   </logFactoryAdapter>
  </logging>		
 </iBATIS>

The configType value extenral tells IBatisNet that log4net has already
been configured.

--- Brian Elcock <br...@gmail.com> wrote:

> Hello All.
> 
> I'm struggling with getting logging setup to log all
> prepared/executed
> SQL statements. I am using .NET 1.1, Log4Net 1.2.9.0,
> IBatisNet.DataMapper 1.3.0.0. I can write to the log just fine from
> within the application when I'm testing, but I can't get iBatis to
> log
> the SQL statements. I've looked at the developer guide, and it seems
> pretty straightforward, but I'm clearly missing something somewhere.
> 
> My solution is broken up into 3 separate projects:
> 
> 1. Domain
> 2. Model (where all the iBatis interaction lives)
> 3. Web
> 
> Any help would be greatly appreciated.
> 
> Here are the relevant parts of my configuration:
> 
> 	<configSections>
> 		<sectionGroup name="iBATIS">
> 			<section name="logging"
> type="IBatisNet.Common.Logging.ConfigurationSectionHandler,
> IBatisNet.Common" />
> 		</sectionGroup>
> 		<section name="log4net"
> type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
> 	</configSections>
> 	
> 	<iBATIS>
> 		<logging>
> 			<logFactoryAdapter
> type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA,
> IBatisNet.Common.Logging.Log4Net">
> 				<arg key="configType" value="file" />
> 				<arg key="configFile" value="Log4Net.config" />
> 			</logFactoryAdapter>
> 		</logging>
> 	</iBATIS>
> 
> 	<log4net>
> 
> 		<!-- Define some output appenders -->
> 		<appender name="RollingLogFileAppender"
> type="log4net.Appender.RollingFileAppender">
> 			<file value="log.log" />
> 			<appendToFile value="true" />
> 			<maximumFileSize value="5MB" />
> 			<maxSizeRollBackups value="-1" />
> 			<layout type="log4net.Layout.PatternLayout">
> 				<conversionPattern value="%5level [%date] %-40.40logger{2}
> %message%newline" />
> 			</layout>
> 		</appender>
> 		
> 		<!-- OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL -->
> 		<!-- Set root logger level to ERROR and its appenders -->
> 		<root>
> 			<level value="ALL" />
> 			<appender-ref ref="RollingLogFileAppender" />
> 		</root>
> 		
>         <logger name="IBatisNet">
> 			<appender-ref ref="RollingLogFileAppender" />
>         </logger>
> 
> 		<logger
> name="IBatisNet.DataMapper.Commands.DefaultPreparedCommand">
> 			<level value="ALL" />
> 		</logger>
> 		
> 	</log4net>
>