How to check if the compiler has an error.

Is there a way through C# to detect if the compiler receives a warning or an error? I am looking for an event based way, but alternatives would work. I don’t necessarily need the cause of the error just the fact that an error occurred in the first place. I imagine it’s buried in UnityEditor somewhere. Any help is appreciated.

You can register a log handler callback and intercept the log messages. That might give you what you want? The catch is that the logging threaded so anything you do there has to be thread safe…

Application.RegisterLogCallbackThreaded(LogHandler);

I use this to write log messages to my console…

void LogHandler(string logString, string stackTrace, LogType type)
{
    lock (thisLock)
    {
        Console.WriteLine(logString);
        LogInternal(logString, stackTrace, type);
    }
}

Oh, as I write this there’s a non-threaded version of this too - Application.RegisterLogCallback