Learn more about SQL Server tools

mssqltips logo

Tutorials          DBA          Dev          BI          Career          Categories          Webcasts          Whitepapers          Today's Tip          Join

Tutorials      DBA      Dev      BI      Categories      Webcasts

DBA    Dev    BI    Categories


Configuring SQL Agent Jobs to Write to Windows Event Log

By:   |   Read Comments (4)   |   Related Tips: More > SQL Server Agent

ALERT: Did you know 66% of DBAs say their workload is increasing! - Click here to learn more.

SQL agent jobs are not created with notifications enabled by default. When creating a new job from within SQL Server Management Studio, you will see the following screen when navigating to the Notifications page.

You have several options on the Notifications page. You could send an email, a page, a net send, write to the application event log, or you could delete the job (which is hardly what I would call a 'notification').

A best practice for job management would be to write information to the application event log in the event of a job failure. Some monitoring tools and software, such as Operations Manager, relies on information being written to the event logs. If no information is being logged than it is possible you could be missing some valuable alerts.

In this tip I will go over how to set this up and also a simple way to turn this on for all of your jobs.

When creating SQL Agent jobs, make certain to configure the job to write to the application event log when the job fails.

Run this to find details on the event notifications for the jobs currently defined on your instance:

 SELECT [name], [notify_level_eventlog]
 FROM msdb..sysjobs

A sample result set is as follows:

The sample result set lists the four possible choices for the [notify_level_eventlog] column:

Column Name


notify_level_eventlog The possible notifications include the following:
    0 - No logging
    1 - Log on success
    2 - Log on failure
    3 - Log on either result

Failures are written to the event log with an eventID of 208. This is important for something like Operations Manager, which has a rule inside the SQL Management Pack that relies on job failures being written to the application event log.

Operations Manager also has a monitor for the last run status of a SQL Agent job.

This monitor does not raise an alert, however. It merely changes the health status of the SQL Agent job target. So you would need to be in the habit of going to your database state views in order to monitor for any failed jobs. Most people, myself included, would prefer to have the failures logged in the application event log and also to generate some email notifications as a reminder.

You can run the following query to find all the jobs defined on your instance that are not doing any logging.

 SELECT [name]
 FROM msdb..sysjobs
 WHERE [notify_level_eventlog] = 0 

If you prefer and are using SQL Server 2008, you could run that same query against all the instances registered in your Central Management Server.

From there, you can update your jobs to write to the application event log on a job failure with one statement.  I like to filter my update statement based upon the name of the job. If you prefer, you can remove the WHERE clause and simply update all of your jobs at the same time.

 UPDATE msdb..sysjobs
 SET [notify_level_eventlog] = 2
 WHERE [name] like 'This one%' 

You will want to be careful if you choose to do so. I have seen some applications that create jobs with a schedule that runs the job every minute. You may not want to write that many failures to your application event log, so be mindful of job schedules when enabling your job notifications.


Next Steps

Last Update:

next webcast button

next tip button

About the author
MSSQLTips author Thomas LaRock Thomas LaRock is a Head Geek at SolarWinds and a Microsoft Certified Master, Microsoft Data Platform MVP, VMware vExpert, and a former Microsoft Certified Trainer with over 20 years’ experience.

View all my tips
Related Resources

Post a comment or let the author know this tip helped.

All comments are reviewed, so stay on subject or we may delete your comment. Note: your email address is not published. Required fields are marked with an asterisk (*).

*Name    *Email    Email me updates 

Signup for our newsletter
 I agree by submitting my data to receive communications, account updates and/or special offers about SQL Server from MSSQLTips and/or its Sponsors. I have read the privacy statement and understand I may unsubscribe at any time.


Wednesday, March 06, 2013 - 10:35:03 AM - Orest Back To Top

How about using SQL Management Pack under SCOM. I searched for a sollution but nothing came up, the only thing i found was:


Friday, August 03, 2012 - 8:24:45 AM - Jan Back To Top


What i'm locking for is the possibility to send SQL Server Logs NOT to the application event. Instead i like to log the events in a seperated eventlog container e.g. SQL-Eventlog. Do you know how to handle this?

Friday, October 23, 2009 - 8:55:00 AM - admin Back To Top


Thank you for the alternative logic and insight. 

Does anyone else from the community have a different way to approach the situation?

Thank you,
The MSSQLTips Team

Friday, October 23, 2009 - 8:49:25 AM - GaryMazzone Back To Top

There are times that I want to do this a little differently.  I want the job to test if a condition exists at the end.  Say I have the job configured to remove any date from a table that is older the 30 days.  I add a step that will check that condition for me (T-SQL statemets in the job step).  If the condition is that the deletes di not complete the delete I don't want the job to report failure of the job just that not all data was deleted. 


Like this:


Declare @daysLeftIn int
SELECT  @daysLeftIn = DATEDIFF(dd, CreateDate, GETUTCDATE())
FROM    tablename WITH ( NOLOCK )
WHERE   Pkfield IN (
        SELECT  MIN(PkField) AS fieldname 
        FROM    tableName WITH ( NOLOCK ) ) ;

If @daysLeftIn > 30
 RAISERROR  (N'The delete of records in the tableName table to 30 days has failed',
    19,1)WITH LOG;


This will mark the job as compelted with success which is true, the job did complete.  But enter a Windows Application Log entry for failure since the delete did not work

Learn more about SQL Server tools