Link Search Menu Expand Document

Logger Configuration

CatraProto uses Serilog for logging. You can use the helper method Logger.CreateDefaultLogger() to create a default logger which prints to console. If no parameter is provided, the method will create a logger with logging level set to LogEventLevel.Information.

You can provide a LoggingLevelSwitch to Logger.CreateDefaultLogger() if you want to change logging level.
You can also specify a console theme using the templateTheme parameter. By default, the Code theme is used.

Example:

var logger = Logger.CreateDefaultLogger(new LoggingLevelSwitch(LogEventLevel.Verbose), TemplateTheme.Literate);

You can also create a logger with your own settings by following the instructions in Serilog’s documentation.

Using your own sink

CatraProto provides a GetExpressionTemplate. This method returns the ExpressionTemplate used by CatraProto for logging to help keep the logging template consistent.

Example:

var myOwnLogger = new LoggerConfiguration()
    .WriteTo
    .File(Logger.GetExpressionTemplate(), "Log.txt", LogEventLevel.Verbose)
    .CreateLogger();