0

I'm writing an application that needs to log error/ exception messages but should still continue execution if the error is not a fatal error. I was thinking of making a method that returns a Task but calling this method as a fire and forget and not wait for response from the method. What is the recommendation, is this a good approach?

  • Why not to log it synchronously? – Roman Bats Aug 8 at 18:01
  • The logging is happening in an external system, like Splunk and I don't want my application to wait till it completes and comes back. – BipinR Aug 8 at 18:04
  • You might better look into the documentation for your logger. It is likely that it can write events in batches, asynchronously, reduceing application latency, so you actually not waiting for each record to be written to the Splunk – Roman Bats Aug 8 at 18:19
1

Fire and forget is what we actually did. The less code you have in the application that is initiating the log message the less code that you have to debug there.

All you actually need to do is write your messages to a logfile(s), and spunk can be configured to process those log(s). You may want to have a process that queues the log messages and that appends them to the file - this would be useful if there are multiple processes or even multiple threads sharing the same log file, but also having n log files is also an option.

Having done this for splunk in C and C++ it is very straight forward.

  • The OP question as stated makes me hope that logging is not used as a substitute for appropriate error handling. – radarbob Aug 12 at 22:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.