How do I write errors to the Application Error Log?
I am trying to catch an exception and write it to the Application Error Log, but cant find any details on how to do this in IRIS health.
Catch ex {Set logger = ##class(%Logger).%GetLogger("MyApp")Do logger.Error($ZError)}Cant seem to find the %Logger class either.
Comments
To log an exception to the Application Error Log in InterSystems IRIS, you should use the %Exception.AbstractException.Log() method. Typically, this is done within the CATCH block of a TRY-CATCH construct. Here is an example in ObjectScript demonstrating this approach:
TRY {
// Code that might throw an exception
}
CATCH ex {
// Log the caught exception to the Application Error Log
DO ex.Log()
}
This method ensures that the details of the exception, including its type and properties, are recorded in the namespace-specific Application Error Log [1].
Sources:
trx this Docs %ETN for Error Logging
You can use the Log() method or do LOG^%ETN(ErrorMessage) inside the Try{} Catch ex{} block and routine to capture the error on Application Errors.