Reputation: 11420
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
Upvotes: 1
Views: 1042
Reputation: 14557
In addition to the behaviour already described by stimms it does one more thing: if the DOTNET_DbgEnableMiniDump
environment variable is set, this will create a crash dump.
You can see the source code for FailFast
at https://github.com/dotnet/runtime/blob/88b5e3d4b77dd8238331ade1b31ac8ddc62f22f7/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs#L181 where you can see exactly what it writes to stderr.
The lines where it decides whether to do anything else with the information it collected (besides writing it to stderr) are here:
You can see that it invokes a method called RhCreateCrashDumpIfEnabled
before aborting the process.
Upvotes: 1
Reputation: 44094
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.
Upvotes: 2