Exception Handling in Quartz .NET

2,388 views
Skip to first unread message

lily

unread,
Mar 23, 2011, 12:47:23 PM3/23/11
to Quartz.NET
How to handle the exceptions in quartz .NET and where to log them.
Right now, is there any way to log the exceptions in quartz (with job
Name, time, and inner exception details)? Or should I create my own
table to log the exceptions? Also, when the exception occurs, i need
to send emails to the admin group.

my code snippet is somewhat like this:

public virtual void Execute(JobExecutionContext context)
{
try
{

// actual job steps to be executed


}
catch (Exception ex)
{
JobExecutionException exception = new
JobExecutionException(ex);
exception.Source = context.JobDetail.FullName;

//log the error
// would like to log the error in sql server tables

//unschedule all triggers
exception.UnscheduleFiringTrigger = true;

//send email notification
}

}

Is this the right way to do it. reply would be appreciated!!

Jay Vilalta

unread,
Mar 23, 2011, 10:48:43 PM3/23/11
to quar...@googlegroups.com
Here's what we do...
We log our exceptions to using log4net. We use a database appender to log
them to a database table. We have a monitoring service that scans that
database table and sends out emails for all error level messages. If you use
log4net or some similar logging framework then it's pretty easy to configure
your appenders so that they write to a table, a file or send an email.

//send email notification
}

}

--
You received this message because you are subscribed to the Google Groups
"Quartz.NET" group.
To post to this group, send email to quar...@googlegroups.com.
To unsubscribe from this group, send email to
quartznet+...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/quartznet?hl=en.


Viji Ranganathan

unread,
Mar 31, 2011, 11:56:31 PM3/31/11
to quar...@googlegroups.com, jay.vilalta
Thanks for your reply Jay. Implemented the exception.
 
Now, trying to implement the windows service. Explored your example on Server.Core, Server.service and Server.console which comes with quartz. 
 
I tried the same, but modified little bit to accomodate the job what I want to do. It is working fine in VS 2008.
 
But, I tried creating the brand new three projects in VS 2010 and did the exact same thing, what I did with VS 2008. Able to create the windows service with installutil.exe. Service is available in the system.
 
But, when I tried to start the service, it did not work. Got the following error:
 
Error #1053: The service did not respond to the start or control request in a timely fashion
 
Any help would be appreciated.
 
Thanks,
Lily 

 

Sunil Soni

unread,
Apr 1, 2011, 12:09:30 AM4/1/11
to quar...@googlegroups.com, Viji Ranganathan, jay.vilalta
Hi Lily,

This error#1053 normally occurs when service throws exception and there is no catch to handle this use try catch block

try below method in your Quartz.Server.Service/program.cs in main method and debug the code.

            #if (!DEBUG)
            System.ServiceProcess.ServiceBase[] ServicesToRun;
            ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };
            System.ServiceProcess.ServiceBase.Run(ServicesToRun);
            #else
            // Debug code: this allows the process to run as a non-service.
            // It will kick off the service start point, but never kill it.
            // Shut down the debugger to exit
            Service1 service = new Service1();
            service.<Your Service's Primary Method Here>();
            // Put a breakpoint on the following line to always catch
            // your service when it has finished its work
            System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
            #endif 

Hope it will help.

-Sunil
Reply all
Reply to author
Forward
0 new messages