We wrap log4net and have had no issues and we have a logger for each class.
I have not swapped it out as your argument suggests, but I don't like to use
any library directly. It shields you not only from swapping out a library,
but from breaking changes in the library you are wrapping. Most of my
wrapper is below... Am I missing something? I'm hopping this would allow me
to switch to say nLog if I wanted...
Public Interface ILogger
Sub Debug(ByVal format As String, ByVal ParamArray args() As Object)
Sub Info(ByVal format As String, ByVal ParamArray args() As Object)
Sub Warn(ByVal format As String, ByVal ParamArray args() As Object)
Sub [Error](ByVal format As String, ByVal ParamArray args() As
Object)
Sub Fatal(ByVal format As String, ByVal ParamArray args() As Object)
Sub Debug(ByVal format As String, ByVal exception As Exception,
ByVal ParamArray args() As Object)
Sub Info(ByVal format As String, ByVal exception As Exception, ByVal
ParamArray args() As Object)
Sub Warn(ByVal format As String, ByVal exception As Exception, ByVal
ParamArray args() As Object)
Sub [Error](ByVal format As String, ByVal exception As Exception,
ByVal ParamArray args() As Object)
Sub Fatal(ByVal format As String, ByVal exception As Exception,
ByVal ParamArray args() As Object)
ReadOnly Property IsDebugEnabled() As Boolean
ReadOnly Property IsInfoEnabled() As Boolean
ReadOnly Property IsWarnEnabled() As Boolean
ReadOnly Property IsErrorEnabled() As Boolean
ReadOnly Property IsFatalEnabled() As Boolean
End Interface
Public NotInheritable Class LogManager
Public Shared Sub Configure(ByVal configFile As FileInfo)
If configFile Is Nothing Then
Throw New System.ArgumentNullException("configFile")
End If
System.Diagnostics.EventLog.WriteEntry( _
String.Format("{0}.LogManager",
Process.GetCurrentProcess.ProcessName), _
String.Format("Configuring logging using configuration file
{0}", configFile.FullName))
log4net.Config.XmlConfigurator.ConfigureAndWatch(configFile)
GetLogger(GetType(LogManager)).Debug("Configured logging using
configuration file {0}", configFile.FullName)
End Sub
Public Shared Function GetLogger(ByVal type As System.Type) As
ILogger
Dim logger As log4net.ILog = _
log4net.LogManager.GetLogger(
System.Reflection.Assembly.GetCallingAssembly(), type)
Return New Log4NetAdapter(logger)
End Function
End Class
Friend Class Log4NetAdapter
Implements ILogger
Private _inner As ILog
Friend Sub New(ByVal log4netLogger As ILog)
_inner = log4netLogger
End Sub
'Implement interface methods delegating to _inner
End Class
On 10/24/07, Owen Corpening <[EMAIL PROTECTED]> wrote:
>
> I second that, but beyond "me-too", the only thing I need that I don't
> have currently is aspect-based logging or the equivalent. In general I have
> concluded that .net aspect technologies are not-there-yet.
>
>
>
> I want to be able to add logging at build or runtime, ideally for runtime
> I can just add a jar with some kind of config file to an existing app and
> get the logging I need …
>
>
>
> Obviously no amount of wrapping will even lead in such a direction …
>
>
>
> Or maybe just-in-time logging, where it will somehow without a performance
> penalty buffer the last bit of logging then when an exception happens start
> logging 5 minutes ago ….
>
>
>
> As for wrapping for "down the road" I have not seen many applications even
> make it down the road … they all keep getting rewritten or close to it as
> new technologies keep arriving … so log4net being the best-in-breed I say
> use it ….
>
>
>
> owen
>
>
> ------------------------------
>
> *From:* Peter Drier [mailto:[EMAIL PROTECTED]
> *Sent:* Wednesday, October 24, 2007 9:05 AM
> *To:* Log4NET User
> *Subject:* Re: Newbie: Log4Net or MS Logging Application Block?
>
>
>
> I've seen many people wrap log4net just so they could swap it out down the
> road..
>
> Doing that, you lose the context sensitivity of having a logger in each
> class.. one of log4net's greatest strengths..
>
> And I've never ever seen it actually replaced down the road.. It makes
> much more sense to create a custom appender to write to whatever system you
> need down the road, while still using log4net as the plumbing within your
> application.
>
> I'd advise HEAVILY against wrapping log4net to everyone. You will be
> trading a strength for a sense of flexibility you'll never actually use.
>
> -Peter
>
> On 10/23/07, *shaeney* <[EMAIL PROTECTED]> wrote:
>
>
>
>
> José Joye wrote:
> >
> > However. in order not to be too hardly tight to log4net, we decided
> > to build a facade to abstract the Logging framework. This was done in
> > order to easily switch the logging framework we use behind the
> > scene.
> >
> > José
> >
>
> Thanks Jose, I had already decided to take that approach in case we wanted
> to swap out the underlying framework at some point.
>
> I am going to produce a test-bed app using both frameworks and see how I
> get
> on with both synchronous and asynchronous messaging. If I get time, I will
> move onto logging from different AppDomains etc
>
> Cheers,
> Steve
> --
> View this message in context:
> http://www.nabble.com/Newbie%3A-Log4Net-or-MS-Logging-Application-Block--tf4669838.html#a13362856
> Sent from the Log4net - Users mailing list archive at Nabble.com.
>
>
>