问题
I am running a C# windows console application and passing in a couple of arguments via Task Scheduler. It runs all day loading flat file data created by other applications into SQL server. The program fails intermittently and I have Try/Catch logic that writes information regarding the exception using Console.WriteLine().
So basically I need to track down the location of the console output so I can take steps to eliminate the intermittent failures. I've had a good look around online thinking this must be a fairly common requirement to diagnose errors from Task Scheduler scheduled apps. My online search has revealed a couple of work around solutions but no direct answer as to where the console output goes when running a c# console application directly via Task Scheduler.
The two workarounds I have seen are:
(1) Get Task Scheduler to run a windows batch script (.bat file) instead of running the console app (.exe file) directly. Within the batch script use ">" or ">>" to redirect the console output to a flat file (e.g C:\app\myapp.exe arg1 arg2 > "C:\log\myapp_console_output.txt")
(2) A very similar solution is to get Task Scheduler to run the windows command line cmd.exe with /C option and passing arguments into cmd.exe to run my console app and also redirect the console output. e.g. something like: cmd.exe /C "C:\app\myapp.exe" arg1 arg2 > "C:\log\myapp_console_output.txt"
While I acknowledge that the above workarounds may well help me to capture future failures it doesnt really help me to track down output from the intermittent failures that have already occurred. They also seem quite messy workarounds to achieve what I would have thought was a pretty common standard requirement.
Can anyone please confirm that the console output is definitely not retained somewhere when running a c# console app directly via Task Scheduler?
来源:https://stackoverflow.com/questions/50163441/where-is-task-scheduler-console-output-c-console-app