Writing to Windows Event Log using TSQL

  • I am able to write to Windows Event Log using xp_LogEvent. My question, is there a way to write, or make an entry into the Windows Event Log using TSQL and avoid having "Error" preceding the event log message? What I am desiring to insert into the Windows Event Log is not an error, but simply an event that is informational.

  • It depends on how you're marking the event. Use a severity of "INFORMATIONAL" or "WARNING" instead of "ERROR"

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • That's the problem. Even if I put the severity at 'Informational' or 'Warning' the body of the event still writes the event as an error.

    Here is my sample script:

    EXEC sys.xp_logevent 101010,'My Event Log Message', 'informational'

    This is what the resulting event log entry looks like:

    Error: 101010 Severity: 15 State: 1 My Event Log Message

  • I don't think that its being done by SQL Server, I think that it's the Event Viewer itself formatting it that way. If you look at the raw data, there's no "Error: ", etc. in there.

    This must just be the format that the Event Viewer uses for all such SQL Server messages.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • So I assume that the answer to my question is: "It is not possible to write a message to the Windows Event Log using TSQL without "Error" being a component of the event log entry."

  • rerichards (3/5/2014)


    So I assume that the answer to my question is: "It is not possible to write a message to the Windows Event Log using TSQL without "Error" being a component of the event log entry."

    Yeah. This is because you are using error raising function to log the message. This is same with xp_logevent or RAISEERROR functions as both of their syntaxes have arguments that are recognized as errors by the event viewer.

    --

    SQLBuddy

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply