Writing to Event Log (multiple lines in the description)

Discussion in 'Scripting' started by Marco Shaw, May 10, 2005.

  1. Marco Shaw

    Marco Shaw Guest

    I want to write events to the Event Log for testing purposes. I've played
    with utilities like logevent.exe and eventcreate.exe, but these don't seem
    to be able to produce messages that span more than one line.

    An example of a description that I need to duplicate:

    The VB Application identified by the event source logged this Application
    xyz: Thread ID: 3420 ,Logged: Source: [xyz]

    Area: [xyz: App Server Request Failed]

    Error Code: [-2147012867]

    Message: [A connection with the server could not be established]

    How can I do this? Can it be done with some kind of scripting or will I
    have to get deeper into VB?

    I then need to figure out how I can script to search for these multi-line


    marco AT nbnet DOT nb DOT ca
    Marco Shaw, May 10, 2005
    1. Advertisements

  2. Hello Marco,
    try it like this:

    'script to write to application eventlog
    dim oWSH
    dim sMsg

    set oWSH=CreateObject("WScript.Shell")
    sMsg="Line1" & vbCrLf & vbCrLf & "Line2"

    oWSH.logevent 4, sMsg

    Martin Peters, May 10, 2005
    1. Advertisements

  3. Marco Shaw

    Jim Vierra Guest

    Try this for scripts.

    Dim sh
    Set sh = CreateObject("WScript.Shell")
    strmeszage = "This Is line 1" & VbCrLf & " This is Line 2"
    iEventID = 2 '0,1,2
    strComputer = "omega"
    sh.LogEvent iEventID,strmeszage, strComputer
    Jim Vierra, May 10, 2005
  4. Marco Shaw

    Jim Vierra Guest

    For command line utilities you can usually add "\n" in the string to cause
    inserted line feeds (newline).
    Jim Vierra, May 10, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.