How to properly return error message from Console to SQL Server Agent

Viewed 2979

I have a C# Console application that will be run from SQL Server agent. If the console application fail, i would like to have the error message shown in the SQL Server agent history log. But it doesnt seem to grab anything from the console app. It only says:

Message Executed as user: domain\account. The step did not generate any output. Process Exit Code 1. The step failed.

So how should i built my console application so that the SQL Server agent would print the error message instead of the "The step did not generate any output." message?

Here's a simple code that i have tested:

class Program
{
    static void Main(string[] args)
    {
        var x = 0;

        // division by zero error
        var y = 1 / x;


        //Console.Error.WriteLine("error message");
    }
}
1 Answers
Related