You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by Ron Grabowski <ro...@yahoo.com> on 2005/06/30 06:22:53 UTC
IBatisNet.Common.Logging
Now that we have our own LogManager, we could borrow NLog's idea of
GetCurrentClassLogger() to return the logger for the current class
instead of the usual System.Reflection... way:
// current way
ILog log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType
);
// less verbose
ILog log = LogManager.GetCurrentClassLogger();
I haven't looked at NLog's implementation of GetCurrentClassLogger()
but I would imagine it involves digging through the stack:
StackTrace callStack = new StackTrace();
StackFrame frame = callStack.GetFrame(1); // 2 ???
MethodBase method = frame.GetMethod();
Type declaringType = method.DeclaringType; // ???
return LogManager.GetLogger(declaringType);
One could argue that doing that is "slower". A counter-argument would
be that the System.Reflection... call is slow compared to:
ILog log = LogManager.GetLogger("IBatisNet.DataAccess.DaoManager");
Its a really a non-issue since the logger is static and the call only
happens once.
Could NoOpLogger (and/or all the built-in log implementations) be
marked as sealed? I can't think of a case where it would be extended.
I'm in favor of making our ILog match log4net's ILog:
http://tinyurl.com/ch9b7
http://cvs.apache.org/viewcvs.cgi/logging-log4net/src/ILog.cs?rev=1.10&view=markup
The new beta has overloads similiar to the StringBuilder's AppendFormat
method:
DebugFormat(string format, params object[] args)
It makes things slightly cleaner:
_logger.Debug("Open Connection [{0}] to [{1}].",
_connection.GetHashCode(), // 0
_dataSource.Provider.Description)); // 1
Perhaps the SimpleLogger could have an additional option indicating
whether it should write to the Console.Out, System.Diagnostic.Trace, or
both:
// Print to the appropriate destination
System.Console.Error.WriteLine( sb.ToString() );
System.Diagnostics.Trace.WriteLine( sb.ToString() );
I believe NLog and log4net both write to Console.Out rather than
Console.Error.
If there were support for writing to Trace, one could easily redirect
the output using a TraceListener in their App.config file:
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add name="textWriterTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\\IBatisNetLog.txt" />
</listeners>
</trace>
</system.diagnostics>
I wonder if these two lines are the same. I forgot that C# had a
PadRight :-)
sb.Append(string.Format("[{0}]",level.ToString().ToUpper()).PadRight(8));
sb.AppendFormat("[{0,-8}],level.ToString().ToUpper());
- Ron
Re: IBatisNet.Common.Logging
Posted by Ron Grabowski <ro...@yahoo.com>.
Jarosław Kowalski's Sooda project:
http://svn.sav.net/repos/sooda/trunk/Sooda/src/
has support for multiple loggers as well. We could make the logging
adapters seperate projects (similiar to the NHibernate extensions) and
default to using the NoOpLogger. That would remove the dependency on
log4net which means IBatisNet may be able to be more easily integrated
with other projects. Users who wanted very basic logging (to make sure
their config files were being read and processed correctly) could use
one of the built in loggers to verify this information.
With the way things are now, if I wanted to use NLog as my logger I am
required to have a copy of log4net.dll in my bin folder.
--- Gilles Bayon <ib...@gmail.com> wrote:
> On 6/30/05, Ron Grabowski <ro...@yahoo.com> wrote:
> >
> > Will the reference to log4net in IBatisNet.Common be going away at
> some
> > point before the next release?
>
> Don't think, to do this we must remove Log4NetLogger,
> Log4NetLoggerFA
Re: IBatisNet.Common.Logging
Posted by Gilles Bayon <ib...@gmail.com>.
On 6/30/05, Ron Grabowski <ro...@yahoo.com> wrote:
>
> Will the reference to log4net in IBatisNet.Common be going away at some
> point before the next release?
Don't think, to do this we must remove Log4NetLogger, Log4NetLoggerFA
The built-in logging implementations should probably have checks around
> the logging call:
>
> public void Debug(object message, Exception e)
> {
> if (_log.IsDebugEnabled)
> {
> _log.Debug( message, e );
> }
> }
The *IBatisNet.Common.Logging*
is justa wrapper arround logging framework and it's not his responsability
to check if the the level is enabled.
I'm not sure how final your code is yet Gilles. I didn't want to go
> messing around changing code if you were still double-checking things.
>
> --- Ron Grabowski <ro...@yahoo.com> wrote:
>
> > Now that we have our own LogManager, we could borrow NLog's idea of
> > GetCurrentClassLogger() to return the logger for the current class
> > instead of the usual System.Reflection... way:
> >
> > // current way
> > ILog log =
> >
> LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod
> ().DeclaringType
> > );
> >
> > // less verbose
> > ILog log = LogManager.GetCurrentClassLogger();
> >
-1 not an issue
> I haven't looked at NLog's implementation of GetCurrentClassLogger()
> > but I would imagine it involves digging through the stack:
> >
> > StackTrace callStack = new StackTrace();
> > StackFrame frame = callStack.GetFrame(1); // 2 ???
> > MethodBase method = frame.GetMethod();
> > Type declaringType = method.DeclaringType; // ???
> > return LogManager.GetLogger(declaringType);
> >
> > One could argue that doing that is "slower". A counter-argument would
> > be that the System.Reflection... call is slow compared to:
> >
> > ILog log = LogManager.GetLogger("IBatisNet.DataAccess.DaoManager");
> >
> > Its a really a non-issue since the logger is static and the call only
> > happens once.
> >
> > Could NoOpLogger (and/or all the built-in log implementations) be
> > marked as sealed? I can't think of a case where it would be extended.
> >
+1
> I'm in favor of making our ILog match log4net's ILog:
> >
> > http://tinyurl.com/ch9b7
> >
>
> http://cvs.apache.org/viewcvs.cgi/logging-log4net/src/ILog.cs?rev=1.10&view=markup
I haven't seen but +1 (you can do it :-)
> The new beta has overloads similiar to the StringBuilder's
> > AppendFormat
> > method:
> >
> > DebugFormat(string format, params object[] args)
> >
> > It makes things slightly cleaner:
> >
> > _logger.Debug("Open Connection [{0}] to [{1}].",
> > _connection.GetHashCode(), // 0
> > _dataSource.Provider.Description)); // 1
> >
> > Perhaps the SimpleLogger could have an additional option indicating
> > whether it should write to the Console.Out, System.Diagnostic.Trace,
> > or
> > both:
> >
+1
Another way will be to replace it with
- ConsoleOutLogger
- ConsoleErrorLogger
- TraceLogger
implementation
> // Print to the appropriate destination
> > System.Console.Error.WriteLine( sb.ToString() );
> > System.Diagnostics.Trace.WriteLine( sb.ToString() );
> >
> > I believe NLog and log4net both write to Console.Out rather than
> > Console.Error.
> >
> > If there were support for writing to Trace, one could easily redirect
> > the output using a TraceListener in their App.config file:
> >
> > <system.diagnostics>
> > <trace autoflush="true">
> > <listeners>
> > <add name="textWriterTraceListener"
> > type="System.Diagnostics.TextWriterTraceListener"
> > initializeData="C:\\IBatisNetLog.txt" />
> > </listeners>
> > </trace>
> > </system.diagnostics>
> >
> > I wonder if these two lines are the same. I forgot that C# had a
> > PadRight :-)
> >
> >
> sb.Append(string.Format("[{0}]",level.ToString().ToUpper()).PadRight(8));
> > sb.AppendFormat("[{0,-8}],level.ToString().ToUpper());
> >
> > - Ron
> >
>
>
Re: IBatisNet.Common.Logging
Posted by Ron Grabowski <ro...@yahoo.com>.
Will the reference to log4net in IBatisNet.Common be going away at some
point before the next release?
The built-in logging implementations should probably have checks around
the logging call:
public void Debug(object message, Exception e)
{
if (_log.IsDebugEnabled)
{
_log.Debug( message, e );
}
}
I'm not sure how final your code is yet Gilles. I didn't want to go
messing around changing code if you were still double-checking things.
--- Ron Grabowski <ro...@yahoo.com> wrote:
> Now that we have our own LogManager, we could borrow NLog's idea of
> GetCurrentClassLogger() to return the logger for the current class
> instead of the usual System.Reflection... way:
>
> // current way
> ILog log =
>
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType
> );
>
> // less verbose
> ILog log = LogManager.GetCurrentClassLogger();
>
> I haven't looked at NLog's implementation of GetCurrentClassLogger()
> but I would imagine it involves digging through the stack:
>
> StackTrace callStack = new StackTrace();
> StackFrame frame = callStack.GetFrame(1); // 2 ???
> MethodBase method = frame.GetMethod();
> Type declaringType = method.DeclaringType; // ???
> return LogManager.GetLogger(declaringType);
>
> One could argue that doing that is "slower". A counter-argument would
> be that the System.Reflection... call is slow compared to:
>
> ILog log = LogManager.GetLogger("IBatisNet.DataAccess.DaoManager");
>
> Its a really a non-issue since the logger is static and the call only
> happens once.
>
> Could NoOpLogger (and/or all the built-in log implementations) be
> marked as sealed? I can't think of a case where it would be extended.
>
> I'm in favor of making our ILog match log4net's ILog:
>
> http://tinyurl.com/ch9b7
>
http://cvs.apache.org/viewcvs.cgi/logging-log4net/src/ILog.cs?rev=1.10&view=markup
>
> The new beta has overloads similiar to the StringBuilder's
> AppendFormat
> method:
>
> DebugFormat(string format, params object[] args)
>
> It makes things slightly cleaner:
>
> _logger.Debug("Open Connection [{0}] to [{1}].",
> _connection.GetHashCode(), // 0
> _dataSource.Provider.Description)); // 1
>
> Perhaps the SimpleLogger could have an additional option indicating
> whether it should write to the Console.Out, System.Diagnostic.Trace,
> or
> both:
>
> // Print to the appropriate destination
> System.Console.Error.WriteLine( sb.ToString() );
> System.Diagnostics.Trace.WriteLine( sb.ToString() );
>
> I believe NLog and log4net both write to Console.Out rather than
> Console.Error.
>
> If there were support for writing to Trace, one could easily redirect
> the output using a TraceListener in their App.config file:
>
> <system.diagnostics>
> <trace autoflush="true">
> <listeners>
> <add name="textWriterTraceListener"
> type="System.Diagnostics.TextWriterTraceListener"
> initializeData="C:\\IBatisNetLog.txt" />
> </listeners>
> </trace>
> </system.diagnostics>
>
> I wonder if these two lines are the same. I forgot that C# had a
> PadRight :-)
>
>
sb.Append(string.Format("[{0}]",level.ToString().ToUpper()).PadRight(8));
> sb.AppendFormat("[{0,-8}],level.ToString().ToUpper());
>
> - Ron
>