Happy 20th Birthday VB6! Yes, VB6 is still alive even though support ran out 13 years ago. Feel free to razz me but please also provide any insight you might have on this issue.
I have a VB6 EXE on a Citrix farm. Data is obtained via COM+ from another server hosting a VB6 COM+ DLL. The COM+ package is exported and installed on each Citrix machine.
The EXE and the COM+ DLL both write to an old logger. I'm trying to get rid of the old logger in favor of a Log4Net version.
I wrote a .NET COM DLL whose sole purpose is to write to the log.
The EXE logs using the .NET DLL (as long as I put the log.config in the same folder as the EXE) but the COM+ component does not. I've tried copying the log.config into various folders hoping that might be the problem. I also wrote another EXE just to test the .NET DLL and it works.
Just for kicks I tried using late binding on the COM+ DLL but that didn't help either. I have the .Net COM DLL registered on the Citrix machine as well as the COM server.
I also attempted to write to the event log from vb6 -- both failed.
I am certain my COM+ DLL's are being implemented as no logs are being written to the old logger. Also, when running from my local machine I get logs from my EXE and the COM+ DLL.
Here's some code...
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
The Event log is a side note -- I'm trying to write to something just so I can debug. I guess my next step will be trying to write to a text file.
Maybe this is a permission issue? Both Citrix and the COM+ server is Win Server 2008 R2 Standard SP1 / 64 bit
Any ideas?