Announcement

Collapse
No announcement yet.

Writing To NT Event Log

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Writing To NT Event Log

    Hey all! Long time no see. I'm using the LogNTEvent subroutine below
    (don't remember where I got it from), but it's not working quite right.
    I see my error message in the NT Application Event Log, but there is a
    bunch of other junk pre-pended to it. Here's the message in the Event
    Log:

    The description for Event ID ( 1 ) in Source ( My Test Service )
    cannot be found. The local computer may not have the necessary
    registry information or message DLL files to display messages from
    a remote computer. The following information is part of the event:
    My Test Service failed to get global service settings. Error
    Description: [Microsoft][ODBC Microsoft Access Driver] Could not
    find file '(unknown)'..


    My actual error message is in bold. Below is the function I'm using.
    I've seen other posts on Google Newsgroups for similar error messages
    but no real answers. Any clues? Thanks in advance! -Scott


    Code:
    SUB LogNTEvent(Message AS STRING, LogCode AS LONG)
    
        '  This method adds Message to the NT Event Log.
    
        ON ERROR GOTO Error_LogNTEvent
    
        DIM dwdRet AS DWORD
        DIM dwdPtr AS DWORD
        DIM lngHEvent AS LONG
        DIM lngMessageSize AS LONG
        DIM lngRet AS LONG
    
        IF ISTRUE(LogCode AND %EVENTLOG_LEVEL) THEN
            '  This event can be logged.
            lngHEvent = RegisterEventSource(BYVAL %NULL, g_asczServiceDisplayNam)
            IF lngHEvent <> %NULL THEN
                lngMessageSize = LEN(Message) + 1
                dwdPtr = STRPTR(Message)
                lngRet = ReportEvent(lngHEvent, LogCode, 0, 1, BYVAL 0&, 1, 0&, BYCOPY dwdPtr, BYVAL %NULL)
                dwdRet = GetLastError()
                DeregisterEventSource lngHEvent
            END IF
        END IF
    
        EXIT SUB
    
        Error_LogNTEvent:
    
        IF lngHEvent <> %NULL THEN
            DeregisterEventSource lngHEvent
        END IF
    
    END SUB
    ------------------
    Scott Wolfington
    http://www.boogietools.com



    [This message has been edited by Scott Wolfington (edited March 05, 2003).]
    Scott Wolfington
    [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

  • #2
    Scott,

    You'll need to compile a message file, and include it in the resource file of
    the DLL/EXE. The message file is compiled with MC.EXE, which comes with MS
    STUDIO 6.

    The message file (.mc) looks like this:

    Code:
    ;#ifndef _MSADERR_H_
    ;#define _MSADERR_H_
    ;#ifndef FACILITY_WINDOWS
    
    ;//--------------------------------------------------------------------------
    ;//  PABX Group Europe BV - Eventmessages file For VoiceLogging Service
    ;//  Copyright (C) PABX Group Europe BV, 1998, 1999.
    ;//--------------------------------------------------------------------------
    ;MessageId=0x0eff Facility=Interface Severity=CoError SymbolicName=DB_E_BOGUS
    ;Language=English
    ;Dummy ERROR - need this ERROR so that mc puts the above defines
    ;inside the FACILITY_WINDOWS guard, instead OF leaving it empty
    ;.
    ;#ENDIF // FACILITY_WINDOWS
    
    ;//--------------------------------------------------------------------------
    MessageId=0x0001
    Language=English
    Voicelogging NT Engine install completed successfully
    .
    MessageId=0x0002
    Language=English
    ERROR occurred; Voicelogging NT Engine NOT installed
    .
    MessageId=0x0003
    Language=English
    ERROR ocurred; cannot uninstall Voicelogging NT Engine
    .
    MessageId=0x0004
    Language=English
    Voicelogging NT Engine uninstall completed successfully
    .
    MessageId=0x0005
    Language=English
    Voicelogging NT Engine is started
    .
    ;
    The compiler MC.exe then creates a file MSG00001.BIN from it.

    It is included in the resourcefile by adding:
    Code:
    LANGUAGE 0x9,0x1
    1 11 MSG00001.BIN
    You'll also have to set up the path where to find the event messages
    in the registry:
    Code:
      lSubKey = "System\CurrentControlSet\Services\EventLog\System\AppName"
            lKeyHandle = RegCreateKeyEx(%HKEY_LOCAL_MACHINE, lSubKey, 0, "", _                      'registry
                         %REG_OPTION_NON_VOLATILE, %KEY_ALL_ACCESS, BYVAL %NULL, lRet, lPos)        '
            lzStr = AppPath                                                                         '
            RegSetValueEx lRet, "EventMessageFile", 0, %REG_SZ, lzStr, SIZEOF (lzStr)               '
            lVal = %EVENTLOG_ERROR_TYPE OR %EVENTLOG_WARNING_TYPE OR %EVENTLOG_INFORMATION_TYPE     'Note what we are capa-
            RegSetValueEx lRet, "TypesSupported", 0, %REG_DWORD, lVal, 4                            'ble of logging.
            RegCloseKey lRet                                                                        '
    (AppName is the name of the application, AppPath the complete path and filename,
    lVal holds the types of messages you want to be able to log)
    Hope this gets you started (Took me a while to figure it all out... )


    ------------------
    Peter.
    mailto[email protected][email protected]</A>
    Regards,
    Peter

    Comment


    • #3
      Thanks Peter. I'll give this a try. Almost makes ya want to write
      error messages to a text file within the InstallDir instead of the
      NT event log. Thanks again!

      Cheers,
      Scott


      ------------------
      Scott Wolfington
      http://www.boogietools.com


      [This message has been edited by Scott Wolfington (edited March 05, 2003).]
      Scott Wolfington
      [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

      Comment


      • #4
        Hey Peter!

        The info you gave me worked. Now, the only problem I'm having
        is that my "Error Message" text is not being displayed. The bold text
        from above:

        My Test Service failed to get global service settings. Error
        Description: [Microsoft][ODBC Microsoft Access Driver] Could not
        find file '(unknown)'..


        I'll keep playin' around with this.

        Scott


        ------------------
        Scott Wolfington
        http://www.boogietools.com


        [This message has been edited by Scott Wolfington (edited March 05, 2003).]
        Scott Wolfington
        [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

        Comment


        • #5
          Scott,

          If The MessageID used by ReportEvent is present, the message in the messagefile
          is used.
          If you want to display a free message (not defined in the message file) use

          Code:
          MessageId=0x00FF
          Language=English
          %1
          Then everytime you use 255 as error, %1 is replaced by the string data from
          ReportEvent. I agree it's a very unfriendly way to get some logging done....


          ------------------
          Peter.
          mailto[email protected][email protected]</A>

          [This message has been edited by Peter Lameijn (edited June 18, 2001).]
          Regards,
          Peter

          Comment


          • #6
            Thanks again Peter! I'll give that a try tonight.

            ------------------
            Scott Wolfington
            http://www.boogietools.com


            [This message has been edited by Scott Wolfington (edited March 05, 2003).]
            Scott Wolfington
            [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

            Comment


            • #7
              Hey Peter!

              Workin' beautifully. Thanks so much for your help.

              Scott


              ------------------
              Scott Wolfington
              http://www.boogietools.com


              [This message has been edited by Scott Wolfington (edited March 05, 2003).]
              Scott Wolfington
              [url="http://www.boogietools.com"]http://www.boogietools.com[/url]

              Comment

              Working...
              X