Skip to content

Commit

Permalink
Fix logging
Browse files Browse the repository at this point in the history
  • Loading branch information
galeaspablo committed Jan 4, 2025
1 parent 7454953 commit 60b5920
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ILogger<CommandController> logger

protected void ProcessCommand(Command command, CommandHandler commandHandler) {
try {
_logger.LogDebug("Starting to process command: {CommandType}", command.GetType().Name);
_postgresTransactionalEventStore.BeginTransaction();
_mongoTransactionalProjectionOperator.StartTransaction();
commandHandler.HandleCommand(command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ protected string ProcessProjectionHttpRequest(
ProjectionHandler projectionHandler,
string projectionName) {
try {
_logger.LogDebug("Starting to process projection for event name: {EventName}", ambarHttpRequest.SerializedEvent.EventName);
var @event = _deserializer.Deserialize(ambarHttpRequest.SerializedEvent);

_mongoOperator.StartTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ILogger<QueryController> logger

protected object ProcessQuery(Query query, QueryHandler queryHandler) {
try {
_logger.LogDebug("Starting to process query: {QueryType}", query.GetType().Name);
_mongoTransactionalProjectionOperator.StartTransaction();
var result = queryHandler.HandleQuery(query);
_mongoTransactionalProjectionOperator.CommitTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ILogger<ReactionController> logger

protected string ProcessReactionHttpRequest(AmbarHttpRequest ambarHttpRequest, ReactionHandler reactionHandler) {
try {
_logger.LogDebug("Starting to process reaction for event name: {EventName}", ambarHttpRequest.SerializedEvent.EventName);
_postgresTransactionalEventStore.BeginTransaction();
_mongoTransactionalProjectionOperator.StartTransaction();
reactionHandler.React(_deserializer.Deserialize(ambarHttpRequest.SerializedEvent));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ namespace CreditCardEnrollment.Common.Util;

public class Logger : ConsoleFormatter
{
public Logger() : base("MainLogger")
{
}
public Logger() : base("MainLogger") { }

public override void Write<TState>(
in LogEntry<TState> logEntry,
Expand All @@ -21,7 +19,12 @@ public override void Write<TState>(
}

var threadId = Thread.CurrentThread.ManagedThreadId;
var category = logEntry.Category ?? "Unknown";
var timestamp = DateTimeOffset.Now.ToString("[yyyy-MM-dd HH:mm:ss.fff] ");
textWriter.WriteLine($"{timestamp} [{threadId}] [{logEntry.LogLevel}] {message}");
textWriter.WriteLine($"{timestamp} [{threadId}] [{category}] [{logEntry.LogLevel}] {message}");

if (logEntry.Exception != null) {
textWriter.WriteLine($"Exception: {logEntry.Exception}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@
options.LogToStandardErrorThreshold = LogLevel.Error;
}).AddConsoleFormatter<Logger, ConsoleFormatterOptions>();

logging.AddFilter("CreditCardEnrollment", LogLevel.Debug);

logging.SetMinimumLevel(LogLevel.Debug);

logging.AddFilter("CreditCardEnrollment", LogLevel.Debug);
logging.AddFilter("Microsoft", LogLevel.Information);
});

var app = builder.Build();
Expand Down

0 comments on commit 60b5920

Please sign in to comment.