SQL Server Agent Jobs Log custom messages in Job History

荒凉一梦 提交于 2019-12-01 09:56:00

问题


Is it possible to log custom messages from your SQL Server Agent job in the job history messages? If not what's the best way to go about doing such a thing?


回答1:


For T-SQL job steps, you can use the print statement. For CmdExec steps, use Console.Writeline in your executable. If there is a lot of output, then by default SQL Agent will not keep all of, and will only keep a certain number of characters. To have it keep all output for a step, you go to the step properties, Advanced, and check the "Include step output in history" checkbox.




回答2:


I haven't done it for a while, but I believe text generated by a PRINT statements in the code executed by the job will end up in the history table. If that doesn't work, RAISERROR with severity less than 11 should do it. (11 and up definitely will, but then jobs are marked as having failed.)



来源:https://stackoverflow.com/questions/21532811/sql-server-agent-jobs-log-custom-messages-in-job-history

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!