Skip to content

Log

Provides debug-only logging that writes to a log file. The file will be located in the current directory, which usually is the directory where your solution file is located.

C# Signature
internal static class Log

The following example writes messages to the log file during a generator run.

C#
using Hertzole.SourceGen;
public static class GeneratorDiagnostics
{
public static void Report()
{
Log.Info("Starting generation.");
Log.Warning("No types were found to generate.");
Log.Error("Failed to generate the output.");
// Clears the log file.
Log.ClearLogs();
}
}

All calls to this class are compiled out in release builds.

Clears the log file.

C# Signature
public static void ClearLogs();

Logs an error message with an ‘ERROR’ prefix.

C# Signature
public static void Error(object message);

The message to log.

Logs an info message with an ‘INFO’ prefix.

C# Signature
public static void Info(object message);

The message to log.

Logs a warning message with a ‘WARNING’ prefix.

C# Signature
public static void Warning(object message);

The message to log.