XenoAtom.Logging includes source generators and analyzers embedded in the core package.
This generator covers two features:
[LogMethod]: generates strongly-typed logging methods from message templates.[LogFormatter]: generates high-performance text formatters from declarative templates.Declare static partial methods with [LogMethod]:
using XenoAtom.Logging;
public static partial class AppLogs
{
[LogMethod(LogLevel.Info, "User {userId} connected from {ip}")]
public static partial void UserConnected(Logger logger, int userId, string ip);
[LogMethod(LogLevel.Error, "Request {requestId} failed", EventId = 42, EventName = "RequestFailed")]
public static partial void RequestFailed(Logger logger, Exception exception, LogProperties properties, int requestId);
}
The generator emits method implementations that:
logger.IsEnabled(level))LogEventIdLoggerExtensions level method{name}, {name,alignment}, {name:format}, {name,alignment:format}{ then {) or two closing braces (} then }).XLG0100: placeholder parameter type may allocate during generated logging.
string, bool, unmanaged ISpanFormattable values.XLG0001: invalid [LogMethod] signatureXLG0002: unsupported log levelXLG0003: invalid message templateXLG0004: unknown template parameterTo create custom text formatters, use [LogFormatter] on a partial record inheriting LogFormatter:
using XenoAtom.Logging;
[LogFormatter("{Timestamp:HH:mm:ss} {Level,-5} {LoggerName} {Text}{? | {Exception}?}")]
public sealed partial record MyFormatter : LogFormatter;
See Log Formatters for usage, template quick reference, and generator setup guidance.