VB6:无法使用我的 ActiveX dll 进行任何日志记录

发布于 2024-11-01 07:29:10 字数 1744 浏览 1 评论 0原文

我正在尝试向似乎卡住运行的 dll 添加日志记录。我尝试简单地添加几个子例程来记录到文件:

Sub PrepareLogging(ByVal strAppName As String)
  Dim objFS As FileSystemObject
  Dim objFolder As Folder
  Dim objFile As File

  Set objFS = New Scripting.FileSystemObject
  g_strAppName = strAppName
  If Not objFS.FolderExists(strLOG_PATH & g_strAppName) Then
    objFS.CreateFolder (strLOG_PATH & g_strAppName)
  End If

  Set objFolder = objFS.GetFolder(strLOG_PATH & g_strAppName)
  For Each objFile In objFolder.Files
    If (Now - objFile.DateCreated) > 60 Then
        objFile.Delete
    End If
  Next
  Set objFolder = Nothing
  Set objFS = Nothing
End Sub

Sub LogAction(ByVal strMsg As String)
  Dim objFS As FileSystemObject
  Dim objText As TextStream
  Set objFS = New Scripting.FileSystemObject

  Set objText = objFS.OpenTextFile(strLOG_PATH & g_strAppName & "\" & Format(Date, "yyyymmdd") & ".log", ForAppending, True)
  objText.WriteLine (Format(Time, "hh:mm:ss") & " - " & strMsg)
  objText.Close
  Set objText = Nothing
  Set objFS = Nothing
End Sub

代码将运行,但它似乎只是忽略所有这些日志记录功能。我知道代码是正确的,因为它可以在其他 dll 和 exe 中工作,我在其中添加了带有这些子例程的模块。我尝试添加一个基本命令来直接记录到事件日志:

App.LogEvent strMsg

但是失败了。如果我尝试使用 Goto ErrorHandler 部分捕获代码中的错误:

ErrorHandler:
  App.LogEvent Err.Number & Err.Description

应用程序完全失败,这样我在登录 Web 服务后甚至无法选择任何选项。我知道问题不在于应用程序日志已满,因为它继续添加新事件。任何关于造成这种情况的建议或想法将不胜感激。

编辑

我很欣赏这些好的建议,但它们没有解决问题。然而,我确实确定,由于某种原因,它不喜欢这一行:

Set objFolder = objFS.GetFolder(strLOG_PATH & g_strAppName)

如果我删除它,作为删除旧文件的部分,它就会起作用。我希望将其放在那里,以防止数百个日志文件堆积在各地的​​服务器上。

结束编辑

I am trying to add logging to a dll that seems to be get stuck running. I have tried simply adding a couple subroutines to log to a file:

Sub PrepareLogging(ByVal strAppName As String)
  Dim objFS As FileSystemObject
  Dim objFolder As Folder
  Dim objFile As File

  Set objFS = New Scripting.FileSystemObject
  g_strAppName = strAppName
  If Not objFS.FolderExists(strLOG_PATH & g_strAppName) Then
    objFS.CreateFolder (strLOG_PATH & g_strAppName)
  End If

  Set objFolder = objFS.GetFolder(strLOG_PATH & g_strAppName)
  For Each objFile In objFolder.Files
    If (Now - objFile.DateCreated) > 60 Then
        objFile.Delete
    End If
  Next
  Set objFolder = Nothing
  Set objFS = Nothing
End Sub

Sub LogAction(ByVal strMsg As String)
  Dim objFS As FileSystemObject
  Dim objText As TextStream
  Set objFS = New Scripting.FileSystemObject

  Set objText = objFS.OpenTextFile(strLOG_PATH & g_strAppName & "\" & Format(Date, "yyyymmdd") & ".log", ForAppending, True)
  objText.WriteLine (Format(Time, "hh:mm:ss") & " - " & strMsg)
  objText.Close
  Set objText = Nothing
  Set objFS = Nothing
End Sub

The code will run, but it seems to just ignore all this logging functionality. I know the code is correct, because it works in other dlls and exes where I've added the module with these subroutines. I tried adding a basic command to log directly to the event log:

App.LogEvent strMsg

But that fails. If I try to catch errors in the code with a Goto ErrorHandler section:

ErrorHandler:
  App.LogEvent Err.Number & Err.Description

The app completely fails, such that I can't even select any options after logging into the web service. I know that the problem is not the application log being full, as it continues to have new events added to it. Any suggestions or ideas on what is causing this would be greatly appreciate.

EDIT

I appreciate the good suggestions, but they did not solve the issue. I did, however, determine that for some reason, it does not like the line:

Set objFolder = objFS.GetFolder(strLOG_PATH & g_strAppName)

If I remove that, as the part to delete old files, it works. I'd like to have that in there, to prevent hundreds of logs files being piled up on servers everywhere.

END EDIT

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木緿 2024-11-08 07:29:10

它可能会因权限问题而失败。我会执行以下操作,不一定按此顺序:

  • 在问题上抛出 ProcMon。它会很快告诉您是否正在尝试写作。它还会指出权限问题。
  • 如果您使用的是 Vista 或 Win 7,请在管理员模式下启动 VB6。

It could be failing for permissions issues. I would do the following, not necessarily in this order:

  • Throw ProcMon on the problem. It will quickly tell you if you are even trying to write. It will also point out permissions issues.
  • Start VB6 in Administrator mode if you are on Vista or Win 7.
撩人痒 2024-11-08 07:29:10

我知道那是什么了。在部分修复后,当坏线出现故障时,我能够注销错误。它给出了类型不匹配错误,我发现它具有文件夹对象的多个定义。固定代码如下所示:

Dim objFolder As Scripting.Folder

解决了它。感谢您的所有投入!

I figured out what it was. After getting it partially fixed, I was able to log out errors when that bad line failed. It was giving a type mismatch error, which I tracked down to it having multiple definitions for the folder object. The fixed code looks like this:

Dim objFolder As Scripting.Folder

That resolved it. Thanks for all input!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文