public function log($level, $message, array $context = []): void
    {
        if (!isset($this->logLevels[$level])) {
            $level = LogLevel::DEBUG;
        }

        $this->exceptionFile = null;

        if ($this->logLevels[$level] < $this->level) {
            return;
        }

        $exceptionFile = null;
        if (isset($context['exception']) && $context['exception'] instanceof \Throwable) {
            $exceptionFile = $this->getExceptionFile($context['exception']);
        }

        if (SEASLOG_EXTENSION) {
            $message .= $exceptionFile ? ' @@  ' . \basename($exceptionFile) : '';

            \SeasLog::log($level, $message, $context);
        } else {
            $message = Dumper::interpolate($message, $context);

            $line = static::formatLogLine($message, $exceptionFile);
            $file = $this->directory . '/' . $level . '.log';

            if (!@\file_put_contents($file, $line . PHP_EOL, FILE_APPEND | LOCK_EX)) { // @ is escalated to exception
                throw new \RuntimeException("Unable to write to log file '$file'. Is directory writable?");
            }
        }

        if ($exceptionFile) {
            $this->logException($context['exception'], $exceptionFile);
        }

        if (\in_array($level, [LogLevel::ERROR, LogLevel::EMERGENCY, LogLevel::CRITICAL, LogLevel::ALERT], true)) {
            $this->sendEmail($message);
        }

        $this->exceptionFile = $exceptionFile;
    }