1

The docs for this method say:

Immediately terminates a process after writing a message to the Windows Application event log, and then includes the message and optional exception information in error reporting to Microsoft.

But what about when deployed to a Linux environment where there's no EventLog or Windows Error Reporting?

I want the benefit of being able to immediately terminate the console app in this way, but it's unclear if this is the right method to use. Is there a better approach for Linux?

The plan is to have my console app running in a Linux container. I'd like the app to be able to terminate, and thus cause the container to terminate, so the infrastructure can spin up a new one. However, I am just getting started with Docker (and my Linux skills are very rusty). So I'm at a loss here...

I will likely have to spin up a small sample and just tinker around, but was hoping to ask the question here in case anyone could provide a quicker answer.

TIA

mikesigs
  • 10,491
  • 3
  • 33
  • 40
  • 1
    Well in a typical docker world .. you have external monitoring processes which are part of the orchestration engine , you can define alerts / rules to scale up or scale down services as required. Besides from my experience , doesn't really matter if application is running on Windows or Linux the exit should always be graceful and should insure that resources and locks are released prior to the exit of the main thread. – Soumen Mukherjee Jan 22 '19 at 20:56

1 Answers1

2

Nothing like trying it out!

using System;

namespace testing
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            System.Environment.FailFast("oh shoot");
            Console.WriteLine("Bye!");
        }
    }
}

Gives me

/tmp/testing$ dotnet run
Hello World!
FailFast:
oh shoot

   at System.Environment.FailFast(System.String, System.Exception)
   at System.Environment.FailFast(System.String)
   at testing.Program.Main(System.String[])

I did not see any additional log messages in anything in /var/log. So I guess it just exists fast and dumps a log to the console.

stimms
  • 42,945
  • 30
  • 96
  • 149