Until agent opens log file all critical errors are written into standard error output (stderr). When started as a service those messages are lost and debugging the error is quite problematic.
The idea is to use eventlog for critical messages if agent has been started as a service. However detecting if agent has been started as a service is another problem.The simplest solution would be to add a command line parameter that would redirect to eventlog all error messaes originally written to stderr. When installing itself as service agent would automatically add this parameter to service launch parameters.