Force sql serve to write to eventlog

The list of all SQL Server errors:

SELECT * FROM sysmessages where msglangid = 1033

I want to force SQL Server to write all errors with a servery higher than X to the operating system event viewer because it's the only way I have to capture sql server errors with my office monitoring tool.

How to do it ?
Who is Participating?
lcohanConnect With a Mentor Database AnalystCommented:
My bad...I should have included more detail:

You can add a new alert as mentioned and under the response you can execute a job instead of sending notification and in that job you can use xp_logevent  stored proc to do what you need:
lcohanDatabase AnalystCommented:
You could set a  New SQL Alert under SQL Agent in SSMS that can do that for you.
migavAuthor Commented:
Help, I don't find how to write to event viwer ..
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Anthony PerkinsCommented:
Perhaps I am being dense but if you want to write to the Event Log, have you considered something like this:
RAISERROR ('Houston we have a problem!', 10, 1) WITH LOG
AlokJain0412Connect With a Mentor Commented:
So, what if you want to log information messages, or messages of low severity? If you wish to have an alert on any errors that are of a severity less that 19, then you have to modify their entry in the sysmessages table to set them to be always logged. You do this using sp_alterMessage with the WITH_LOG option to set the dLevel column to 128 . If a message has been altered to be WITH_LOG, it is always subsequently written to the application log, however the error happens. Even if RAISERROR is executed without the WITH LOG option, the error that you have altered is written to the application log, and is therefore spotted by the alert. There are good reasons for wanting to do this, as it will then log, and optionally alert you to, syntax errors that are normally seen only by the end-user.

  You can force any error that is triggered programmatically to be written to the error log by using the WITH LOG parameter with the RAISERROR command. So, with a user-defined error severity (9) you can log an incident, cause an alert to be fired, which in turn emails someone, or runs a job, simply by using RAISERROR. Naturally, because the job that responds to the alert can be run by the Agent under a different User, you do not need to assign unsafe permissions to the ordinary user. You can use xp_LogEvent if, as is likely, you do not want the user to see the error. (Only the Raiserror call can utilize the 'PrintF' formatting  placeholders in the error messages, so logging the error with a formatted message using xp_logevent results in a literal recording of the message, string format identifiers and all.)

You can read your Forcibly   Logged errors by following parameters  

Example EXEC xp_ReadErrorLog 0, 1, NULL, NULL, @DatelessHour, @CurrentDate
migavAuthor Commented:
Thanks !
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.