Happy 20th Birthday VB6! 是的,即使支持在13年前用完,VB6仍然存在 . 请随意给我留言,但请提供您对此问题的任何见解 .

我在Citrix服务器场上有一个VB6 EXE . 数据是通过COM从托管VB6 COM DLL的另一台服务器获得的 . COM包将导出并安装在每台Citrix计算机上 .

EXE和COM DLL都写入旧的 Logger . 我正试图摆脱旧的 Logger ,转而使用Log4Net版本 .

我写了一个.NET COM DLL,其唯一目的是写入日志 .

使用.NET DLL的EXE日志(只要我将log.config放在与EXE相同的文件夹中),但COM组件不会 . 我已经尝试将log.config复制到各种文件夹中,希望这可能是问题所在 . 我还写了另一个EXE来测试.NET DLL,它的工作原理 .

只是为了踢,我尝试在COM DLL上使用后期绑定,但这也没有帮助 . 我在Citrix计算机和COM服务器上注册了.Net COM DLL .

我还试图从vb6写入事件日志 - 都失败了 .

我确定我的COM DLL正在实现,因为没有日志写入旧的 Logger . 此外,从我的本地计算机运行时,我从我的EXE和COM DLL获取日志 .

这是一些代码......

Here's 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 is the VB6 code being called from both EXE and 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

Here's method 1 I was using to write to the event log:

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

and here's method 2 of writing to the event log

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标准版SP1 / 64位

有任何想法吗?