Skip to content
This repository has been archived by the owner on Feb 25, 2020. It is now read-only.

Commit

Permalink
Added logging code to middleware example
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Eastwood committed Mar 18, 2019
1 parent 98cd738 commit b43bb98
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Networker.Example.Json/Middleware/RoleCheckMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@
using System.Net;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Networker.Common.Abstractions;

namespace Networker.Example.Json.Middleware
{
public class RoleCheckMiddleware : IMiddlewareHandler
{
private readonly ILogger<RoleCheckMiddleware> logger;

public RoleCheckMiddleware(ILogger<RoleCheckMiddleware> logger)
{
this.logger = logger;
}

public async Task<bool> Process(IPacketContext context)
{
var roleAttribute = context.Handler.GetType()
Expand All @@ -21,6 +29,7 @@ public async Task<bool> Process(IPacketContext context)
return true;
}

this.logger.LogCritical("Somebody tried to do something they did not have permission for!");
context.Sender.Send(new NotAllowedResponsePacket());

return false;
Expand Down

0 comments on commit b43bb98

Please sign in to comment.