stride3d/stride · error · ArgumentException

Unsupported log message.

Error message

Unsupported log message.

What it means

GetExceptionText extracts the exception text from a log message but only understands ILogMessage implementations carrying ExceptionInfo and the concrete LogMessage type carrying Exception. Passing any other object throws ArgumentException('Unsupported log message.') because no exception can be extracted.

Solutions

  1. Only pass RichLogFileLogMessage-style messages (with ExceptionInfo) or LogMessage instances
  2. Before calling, check the concrete type: if not LogMessage/rich message, read msg.Exception yourself or pass string.Empty
  3. Implement ILogMessage via LogMessage (or expose ExceptionInfo) on your custom message type

Example fix

// before
var text = LogListener.GetExceptionText(myCustomMessage);
// after
var text = myCustomMessage is LogMessage lm
    ? LogListener.GetExceptionText(lm)
    : (myCustomMessage.Exception?.ToString() ?? string.Empty);
Defensive patterns

Strategy: type-guard

Validate before calling

if (msg is LogMessage || msg?.GetType().GetProperty("ExceptionInfo") != null)
    return LogListener.GetExceptionText(msg);

Type guard

bool hasExceptionText(ILogMessage m) =>
    m is LogMessage || m.GetType().GetProperty("ExceptionInfo") != null;

Try / catch

try { return LogListener.GetExceptionText(msg); }
catch (ArgumentException) { return msg?.Exception?.ToString() ?? string.Empty; }

Prevention

When it happens

Trigger: Calling LogListener.GetExceptionText (or the code path that uses it) with an object implementing ILogMessage that is neither the internal rich-message type nor LogMessage — e.g. a custom ILogMessage implementation or a wrapper/decorator message.

Common situations: Subscribing a custom Action<ILogMessage> or forwarding messages from another logging framework (custom adapters) into GetExceptionText; refactorings that introduced a new ILogMessage type without updating this helper.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/ae5e408952de3669. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core/Diagnostics/LogListener.cs:144

        return TextFormatter(logMessage);
    }

    /// <summary>
    /// Gets the text that describes the exception associated to a particular log message.
    /// </summary>
    /// <param name="message">The log message.</param>
    /// <returns>A textual representation of the exception, or <see cref="string.Empty"/> if no exception is associated to this log message.</returns>
    protected virtual string GetExceptionText(ILogMessage message)
    {
        if (message is SerializableLogMessage serializableLogMessage)
        {
            return serializableLogMessage.ExceptionInfo?.ToString() ?? string.Empty;
        }
        if (message is LogMessage logMessage)
        {
            return logMessage.Exception?.ToString() ?? string.Empty;
        }
        throw new ArgumentException("Unsupported log message.");
    }

    /// <summary>
    /// Performs an implicit conversion from <see cref="LogListener"/> to <see cref="Action{ILogMessage}"/>.
    /// </summary>
    /// <param name="logListener">The log listener.</param>
    /// <returns>The result of the conversion.</returns>
    public static implicit operator Action<ILogMessage>(LogListener logListener)
    {
        return logListener.OnLogInternal;
    }

    private void OnLogInternal(ILogMessage logMessage)
    {
        if (!IsEnabled(logMessage))
            return;

        OnLog(logMessage);

View on GitHub (pinned to 96fad776d2)