Open shaliake opened 1 year ago
This is the setup I use you might want to try that:
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("System", LogEventLevel.Warning)
.Enrich.WithProperty("AppName", appName)
.Enrich.WithEnvironmentName()
.Enrich.FromLogContext()
.Enrich.FromGlobalLogContext()
.WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Information)
.WriteTo.PostgreSQL(dbConnString, LogsTableName, SerilogSettings.GetLogsTableDefinition(), needAutoCreateTable: true, restrictedToMinimumLevel: LogEventLevel.Information)
.CreateLogger();
Also you need to catch exceptions inside your jobs and use injected logger to log them:
public class NotificationJob
{
private readonly ILogger<NotificationJob> _logger;
public TelekomSmsNotificationJob(ILogger<NotificationJob> logger )
{
_logger = logger;
LogContext.PushProperty("Job", nameof(NotificationJob));
}
...
_logger.LogInformation("Sending/scheduling SMS: {@MessageBody}", smsPacket);
}
Hello!
I have added Hangfire to my solution which uses Serilog as Logger. Serilog config:
Hangfire registration:
But still I do not see any failed job logs, only what hangfire does, is there any way to log that exception occurred during job?