An event ID is logging metadata that classifies related log records. A controller action or exception can receive a custom number, allowing records to be grouped, filtered, or audited. section 7.2.5 section 7.2.6
A practical implementation uses the logging API and a centralized convention:
- Pass the event ID as the first parameter to LogInformation or LogError. section 7.2.5 section 7.2.6
- Define constants such as BoardGamesController_Get = 50110 and Error_Get = 50001 in a shared CustomLogEvents class. section 7.2.5 section 7.2.6
- Verify the result in the console, remembering that providers differ in whether and where they display the ID. section 7.2.5
Classifying a controller log
Calling _logger.LogInformation(CustomLogEvents.BoardGamesController_Get, "Get method started.") produces a record associated with event 50110. The constant makes the convention readable and reduces mistyped numeric literals.
Listing 7.1 CustomLogEvents class
namespace MyBGList.Constants
{
public class CustomLogEvents
{
public const int BoardGamesController_Get = 50110;
public const int BoardGamesController_Post = 50120;
public const int BoardGamesController_Put = 50130;
public const int BoardGamesController_Delete = 50140;
public const int DomainsController_Get = 50210;
public const int DomainsController_Post = 50220;
public const int DomainsController_Put = 50230;
public const int DomainsController_Delete = 50240;
public const int MechanicsController_Get = 50310;
public const int MechanicsController_Post = 50320;
public const int MechanicsController_Put = 50330;
public const int MechanicsController_Delete = 50340;
}
}
Browse a complete event-ID naming scheme covering controller operations and their corresponding numeric constants. section 7.2.5
Structured providers may store EventId inside a semistructured Properties value. Because EventId is complex and can contain values such as integers or strings, Serilog can map it to a dedicated database column when configured. section 7.4.5

