VB6 COM + call .Net COM DLL

Happy 20th Birthday VB6! Yes, VB6 is still alive, although support ended 13 years ago. Feel free to annoy me, but please also give any understanding that may arise on this issue.

I have a VB6 EXE on a Citrix farm. Data is received via COM + from another server hosting the VB6 COM + DLL. The COM + package is exported and installed on each Citrix machine.

EXE and COM + DLL write to the old registrar. I am trying to get rid of the old registrar in favor of the Log4Net version.

I wrote a .NET COM DLL whose sole purpose is to write to the log.

EXE logs using the .NET DLL (so far I put log.config in the same folder as the EXE), but the COM + component does not. I tried to copy the log.config file to various folders, hoping this might be a problem. I also wrote another EXE to test the .NET DLL, and it works.

Just for hits I tried using late binding to COM + DLL, but that didn't help either. I have a .Net COM DLL registered on a Citrix machine as well as on a COM server.

I also tried writing to the event log from vb6 - both failed.

I am sure my COM + DLL is implemented as the logs are not written to the old registrar. Also, when working from my local machine, I get the logs from my EXE and COM + DLL.

Here is the code ...

Here is my VB.NET COM logging code

Imports System.IO
Imports log4net

<Assembly: Config.XmlConfigurator(ConfigFile:="Log.config", Watch:=True)>

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

    Public logger As log4net.ILog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)

#Region "COM GUIDs"
    Public Const ClassId As String = "6fae24c7-f86b-4fab-8b49-1d441de5bd18"
    Public Const InterfaceId As String = "223a30c4-ec1e-45a6-82d3-d23cd4c933f9"
    Public Const EventsId As String = "2087d93e-dd38-4cd1-b757-44dee322a8e3"
    Public Property TraceExtension As Object
#End Region

    Public Sub New()
        MyBase.New()

        WriteEvent("New Start")

        If Not log4net.LogManager.GetRepository().Configured Then
            Dim configFileDirectory = (New DirectoryInfo(TraceExtension.AssemblyDirectory)).Parent
            Dim configFile = New FileInfo(configFileDirectory.FullName + "\log.config")

            If configFile.Exists Then
                WriteEvent("New Config Exists")
                log4net.Config.XmlConfigurator.Configure(configFile)
            Else
                WriteEvent(String.Format("The configuration file {0} does not exist", configFile))
                Throw New FileLoadException(String.Format("The configuration file {0} does not exist", configFile))
            End If
        End If

        WriteEvent("New End")

    End Sub

    Private Sub WriteEvent(msg As String, Optional id As Integer = 11)
        Using eventLog As New EventLog("Application")
            eventLog.Source = "CSS"
            eventLog.WriteEntry(msg, EventLogEntryType.Error, id)
        End Using
    End Sub

    Public Sub Debug(msg As String)
        logger.Debug(msg)
    End Sub
    Public Sub Info(msg As String)
        logger.Info(msg)
    End Sub
    Public Sub Warn(msg As String)
        logger.Warn(msg)
    End Sub
    Public Sub Err(msg As String)
        logger.Error(msg)
    End Sub
    Public Sub Fatal(msg As String)
        logger.Fatal(msg)
    End Sub
End Class

, and here the VB6 code is called both from EXE and from COM + DLL.

Public Sub AppLog(ByVal LogType As Integer, ByVal Data As String)
10  On Error Resume Next
20  Dim klog As New KerryLog.Log
30  Data = "EXE > " + Data ' the COM+ DLL has a Prefix of COM instead of EXE

    Select Case LogType
            Case LogTypeNone: klog.Info Data
            Case LogTypeAppStart: klog.Info Data
            Case LogTypeAppEnd: klog.Info Data
            Case LogTypeInfo: klog.Info Data
            Case LogTypeVerbose: klog.Debug Data
            Case LogTypeWarning: klog.Warn Data
            Case LogTypeHandledException: klog.Err Data
            Case LogTypeUnhandledException: klog.Fatal Data
            Case LogTypeAutomated: klog.Info Data
            Case LogTypeUsage: klog.Debug Data
    End Select

40  Set klog = Nothing

1, :

App.StartLogging "", vbLogToNT
App.LogEvent "this is the error message", vbLogEventTypeError

2

Private Declare Function ReportEvent _
    Lib "advapi32.dll" Alias "ReportEventA" ( _
    ByVal hEventLog As Long, _
    ByVal wType As Integer, _
    ByVal wCategory As Integer, _
    ByVal dwEventID As Long, _
    ByVal lpUserSid As Long, _
    ByVal wNumStrings As Integer, _
    ByVal dwDataSize As Long, _
    plpStrings As String, _
    lpRawData As Long) As Long

Private Declare Function RegisterEventSource _
    Lib "advapi32.dll" Alias "RegisterEventSourceA" ( _
    ByVal lpUNCServerName As String, _
    ByVal lpSourceName As String) As Long

Public Sub LogThis(nErrNo As Long, sLogMsg As String, EventType As LogEventTypeConstants)
    Dim hEvent As Log

    hEvent = RegisterEventSource("", "CSS")
    Call ReportEvent(hEvent, EventType, 0, nErrNo, 0, 1, Len(sLogMsg), sLogMsg, 0)
End Sub

- - -, . , .

, ? Citrix, COM + Win Server 2008 R2 Standard SP1/64

?

+4

Source: https://habr.com/ru/post/1695726/


All Articles