This repository was archived by the owner on Feb 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a86b65b
commit 3bb2d13
Showing
5 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MediatR; | ||
using Serilog; | ||
using Serilog.Context; | ||
|
||
namespace Bunt.Core.Infrastructure | ||
{ | ||
public class LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> | ||
{ | ||
private readonly ILogger _logger; | ||
|
||
public LoggingBehavior(ILogger logger) | ||
{ | ||
_logger = logger; | ||
} | ||
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next) | ||
{ | ||
using (LogContext.PushProperty("CorrelationId", Guid.NewGuid())) | ||
using (LogContext.PushProperty("RequestName", typeof(TRequest).FullName)) | ||
{ | ||
try | ||
{ | ||
_logger.Information("Executing {@RequestName} with payload {@RequestPayload}", typeof(TRequest).FullName, request); | ||
return await next(); | ||
} | ||
catch (Exception e) | ||
{ | ||
_logger.Error(e, e.Message); | ||
throw; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using FluentMigrator; | ||
|
||
namespace Bunt.Migrations | ||
{ | ||
[Migration(201712061300)] | ||
public class AddRequestLogTable : Migration | ||
{ | ||
public override void Up() | ||
{ | ||
Execute.Sql(@" | ||
CREATE TABLE [Log] ( | ||
[Id] int IDENTITY(1,1) NOT NULL PRIMARY KEY, | ||
[Message] nvarchar(max) NULL, | ||
[MessageTemplate] nvarchar(max) NULL, | ||
[Level] nvarchar(128) NULL, | ||
[TimeStamp] datetimeoffset(7) NOT NULL, -- use datetime for SQL Server pre-2008 | ||
[Exception] nvarchar(max) NULL, | ||
[Properties] xml NULL, | ||
[LogEvent] nvarchar(max) NULL | ||
) | ||
"); | ||
} | ||
|
||
public override void Down() | ||
{ | ||
Delete.Table("Log"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters