Cobol Code

[Migrated content. Thread originally posted on 19 January 2012]

Hi All,

Does any one know how to COBOLIZE this?

support.microsoft.com/.../301279

Many thanks

Neil.
  • Verified Answer

    (To save everyone else from looking up the MSDN article, it shows how to write to a Windows event log.)

    We've done this in managed COBOL. It's quite straightforward.

    Here's a straight conversion of the VB.NET source from the article:

          $set sourceformat"variable"

          * COBOL version of MS KB 301279

          $set ilusing"System"
          $set ilusing"System.Diagnostics"

           class-id. Module1.
           method-id. Main static.
           01 sSource      string.
           01 sLog         string.
           01 sEvent       string.
           01 sMachine     string.
           01 eLog         type EventLog.
           
           procedure division.
               set sSource to "dotNET Sample App"
               set sLog to "Application"
               set sEvent to "Sample Event"
               set sMachine to "."

               if not type EventLog::SourceExists(sSource sMachine)
                   invoke type EventLog::CreateEventSource(sSource sLog sMachine)
               end-if

               set eLog to new EventLog(sLog sMachine sSource)
               invoke eLog::WriteEntry(sEvent)
               invoke eLog::WriteEntry(sEvent, type EventLogEntryType::Warning, 234, 3 as binary-short)
           end method Main.
           end class Module1.


    You can compile that right from the command line with "cobol filename.cbl ilgen ;".