You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Matthew Easlea <ma...@cosol.com.au> on 2004/05/04 02:17:03 UTC

COM and VB6 with Log4net?

Peoples,

I have the situation where I 70% of my components are written in .NET, but
quite few large legacy components are hanging around in VB6.

I would like to consolidate my logging framework, and as all the vb6
components use the same custom built logging class, I would like to change
the vb6 logging class to use Log4NET.

Has anybody used Log4Net from old COM based languages? I have a basic system
working, I had to write a COM based wrapper class library in .NET - such as
in the code below - but if the log4net community has a default or properly
written and tested interface I would much rather use that. Any plans on
including such an interface in a future version of log4net? Also I have the
obvious problem of missing stack traces, line numbers etc. I think this
would be a much sought after feature that would be really good for many
large companies that are slowly migrating to .NET.

Cheers


Following code has been copied from a class library in Visual Studio 2003.

Imports System
Imports System.IO
Imports log4net
Imports log4net.Config

<ComClass(BPC_Log4Net.ClassId, BPC_Log4Net.InterfaceId,
BPC_Log4Net.EventsId)> _
Public Class BPC_Log4Net

#Region "COM GUIDs"
    ' These  GUIDs provide the COM identity for this class 
    ' and its COM interfaces. If you change them, existing 
    ' clients will no longer be able to access the class.
    Public Const ClassId As String = "EF01DF44-C835-411A-8F33-A3BC048E69AD"
    Public Const InterfaceId As String =
"9EFF2B48-C6CC-428B-99F5-5332B91D1EFC"
    Public Const EventsId As String = "7FD05B38-36B7-425C-B850-9BB05BFC1D2B"
#End Region

    Private ReadOnly log As log4net.ILog = LogManager.GetLogger("COSOL")

    Public Sub LogMessage(ByVal MessageIn As String, ByVal MessageType As
String)
        log.Debug(MessageIn)
    End Sub

    ' A creatable COM class must have a Public Sub New() 
    ' with no parameters, otherwise, the class will not be 
    ' registered in the COM registry and cannot be created 
    ' via CreateObject.
    Public Sub New()
        MyBase.New()
        Dim path As String = " log4netConfig.xml"
        Dim fi As FileInfo = New FileInfo(path)

        log4net.Config.DOMConfigurator.Configure(fi)
        log.Debug("Started")
    End Sub

End Class



RE: COM and VB6 with Log4net?

Posted by rohit s <ro...@yahoo.co.in>.
Hi...
 
now a days we r trying to make a logging service based on log4Net which used by various application ( VB/VC++/.NET app)...
but could not even after using COM Interop. Our code works fine ( no comilation  and runtime error) but Logging is not happening.. We dont know the reason.
 
But i come across your post and like your idea. Can you post your code so that we can used it in our application..
 
Thanks in advance
 
Rohit


Matthew Easlea <ma...@cosol.com.au> wrote:
Hi everybody,

Last time I posted this message nobody seemed to reply. I am about to go
live with the solution as it appears to be working well during our testing
and I was wondering if anybody had any final comments, reasons why I
shouldn't use Log4Net from VB6? 

I've made some small improvements to the code below and will post if anybody
is interested.

Cheers


-----Original Message-----
From: Matthew Easlea [mailto:matthew.easlea@cosol.com.au] 
Sent: Tuesday, 4 May 2004 10:17 AM
To: log4net-user@logging.apache.org
Subject: COM and VB6 with Log4net?

Peoples,

I have the situation where I 70% of my components are written in .NET, but
quite few large legacy components are hanging around in VB6.

I would like to consolidate my logging framework, and as all the vb6
components use the same custom built logging class, I would like to change
the vb6 logging class to use Log4NET.

Has anybody used Log4Net from old COM based languages? I have a basic system
working, I had to write a COM based wrapper class library in .NET - such as
in the code below - but if the log4net community has a default or properly
written and tested interface I would much rather use that. Any plans on
including such an interface in a future version of log4net? Also I have the
obvious problem of missing stack traces, line numbers etc. I think this
would be a much sought after feature that would be really good for many
large companies that are slowly migrating to .NET.

Cheers


Following code has been copied from a class library in Visual Studio 2003.

Imports System
Imports System.IO
Imports log4net
Imports log4net.Config

BPC_Log4Net.EventsId)> _
Public Class BPC_Log4Net

#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class 
' and its COM interfaces. If you change them, existing 
' clients will no longer be able to access the class.
Public Const ClassId As String = "EF01DF44-C835-411A-8F33-A3BC048E69AD"
Public Const InterfaceId As String =
"9EFF2B48-C6CC-428B-99F5-5332B91D1EFC"
Public Const EventsId As String = "7FD05B38-36B7-425C-B850-9BB05BFC1D2B"
#End Region

Private ReadOnly log As log4net.ILog = LogManager.GetLogger("COSOL")

Public Sub LogMessage(ByVal MessageIn As String, ByVal MessageType As
String)
log.Debug(MessageIn)
End Sub

' A creatable COM class must have a Public Sub New() 
' with no parameters, otherwise, the class will not be 
' registered in the COM registry and cannot be created 
' via CreateObject.
Public Sub New()
MyBase.New()
Dim path As String = " log4netConfig.xml"
Dim fi As FileInfo = New FileInfo(path)

log4net.Config.DOMConfigurator.Configure(fi)
log.Debug("Started")
End Sub

End Class




Yahoo! India Matrimony: Find your partner online.

RE: COM and VB6 with Log4net?

Posted by Matthew Easlea <ma...@cosol.com.au>.
Hi everybody,

Last time I posted this message nobody seemed to reply. I am about to go
live with the solution as it appears to be working well during our testing
and I was wondering if anybody had any final comments, reasons why I
shouldn't use Log4Net from VB6? 

I've made some small improvements to the code below and will post if anybody
is interested.

Cheers


-----Original Message-----
From: Matthew Easlea [mailto:matthew.easlea@cosol.com.au] 
Sent: Tuesday, 4 May 2004 10:17 AM
To: log4net-user@logging.apache.org
Subject: COM and VB6 with Log4net?

Peoples,

I have the situation where I 70% of my components are written in .NET, but
quite few large legacy components are hanging around in VB6.

I would like to consolidate my logging framework, and as all the vb6
components use the same custom built logging class, I would like to change
the vb6 logging class to use Log4NET.

Has anybody used Log4Net from old COM based languages? I have a basic system
working, I had to write a COM based wrapper class library in .NET - such as
in the code below - but if the log4net community has a default or properly
written and tested interface I would much rather use that. Any plans on
including such an interface in a future version of log4net? Also I have the
obvious problem of missing stack traces, line numbers etc. I think this
would be a much sought after feature that would be really good for many
large companies that are slowly migrating to .NET.

Cheers


Following code has been copied from a class library in Visual Studio 2003.

Imports System
Imports System.IO
Imports log4net
Imports log4net.Config

<ComClass(BPC_Log4Net.ClassId, BPC_Log4Net.InterfaceId,
BPC_Log4Net.EventsId)> _
Public Class BPC_Log4Net

#Region "COM GUIDs"
    ' These  GUIDs provide the COM identity for this class 
    ' and its COM interfaces. If you change them, existing 
    ' clients will no longer be able to access the class.
    Public Const ClassId As String = "EF01DF44-C835-411A-8F33-A3BC048E69AD"
    Public Const InterfaceId As String =
"9EFF2B48-C6CC-428B-99F5-5332B91D1EFC"
    Public Const EventsId As String = "7FD05B38-36B7-425C-B850-9BB05BFC1D2B"
#End Region

    Private ReadOnly log As log4net.ILog = LogManager.GetLogger("COSOL")

    Public Sub LogMessage(ByVal MessageIn As String, ByVal MessageType As
String)
        log.Debug(MessageIn)
    End Sub

    ' A creatable COM class must have a Public Sub New() 
    ' with no parameters, otherwise, the class will not be 
    ' registered in the COM registry and cannot be created 
    ' via CreateObject.
    Public Sub New()
        MyBase.New()
        Dim path As String = " log4netConfig.xml"
        Dim fi As FileInfo = New FileInfo(path)

        log4net.Config.DOMConfigurator.Configure(fi)
        log.Debug("Started")
    End Sub

End Class