-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated LogListenerParser to fix issue #19
- Loading branch information
catalin.gavan
committed
Oct 16, 2019
1 parent
3d9ed02
commit 4671608
Showing
12 changed files
with
143 additions
and
35 deletions.
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using KissLog.FlushArgs; | ||
using KissLog.Web; | ||
|
||
|
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,48 @@ | ||
using KissLog.Web; | ||
using System.Collections.Generic; | ||
|
||
namespace KissLog.Internal | ||
{ | ||
internal class LogListenerDecorator | ||
{ | ||
public LogListenerDecorator(ILogListener listener) | ||
{ | ||
Listener = listener; | ||
} | ||
|
||
public ILogListener Listener { get; private set; } | ||
public List<string> SkipRequestIds = new List<string>(); | ||
|
||
public void Reset() | ||
{ | ||
SkipRequestIds.Clear(); | ||
SkipRequestIds = new List<string>(); | ||
} | ||
|
||
public bool ShouldSkipOnMessage(Logger logger) | ||
{ | ||
string requestId = logger.DataContainer?.WebProperties?.Request?._KissLogRequestId; | ||
|
||
if (string.IsNullOrEmpty(requestId)) | ||
return false; | ||
|
||
if (SkipRequestIds.Contains(requestId)) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
public bool ShouldSkipOnFlush(HttpRequest request) | ||
{ | ||
string requestId = request?._KissLogRequestId; | ||
|
||
if (string.IsNullOrEmpty(requestId)) | ||
return false; | ||
|
||
if (SkipRequestIds.Contains(requestId)) | ||
return true; | ||
|
||
return false; | ||
} | ||
} | ||
} |
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
33 changes: 26 additions & 7 deletions
33
src/KissLog/Internal/NotifyListeners/NotifyOnBeginRequestService.cs
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 |
---|---|---|
@@ -1,22 +1,41 @@ | ||
using KissLog.Web; | ||
using System.Linq; | ||
using KissLog.FlushArgs; | ||
using KissLog.Web; | ||
|
||
namespace KissLog.Internal | ||
{ | ||
internal static class NotifyOnBeginRequestService | ||
{ | ||
public static void Notify(HttpRequest httpRequest, Logger logger) | ||
{ | ||
if (KissLogConfiguration.Listeners == null || KissLogConfiguration.Listeners.Any() == false) | ||
return; | ||
|
||
foreach (ILogListener listener in KissLogConfiguration.Listeners) | ||
foreach (LogListenerDecorator decorator in KissLogConfiguration.Listeners.Get()) | ||
{ | ||
if (listener == null) | ||
ILogListener listener = decorator.Listener; | ||
|
||
BeginRequestArgs args = new BeginRequestArgs | ||
{ | ||
IsCreatedByHttpRequest = logger.IsCreatedByHttpRequest(), | ||
Request = httpRequest | ||
}; | ||
|
||
if (ShouldUseListener(listener, args) == false) | ||
{ | ||
// make the listener skip all the events for the current request | ||
decorator.SkipRequestIds.Add(args.Request._KissLogRequestId); | ||
|
||
continue; | ||
} | ||
|
||
listener.OnBeginRequest(httpRequest, logger); | ||
} | ||
} | ||
|
||
private static bool ShouldUseListener(ILogListener listener, BeginRequestArgs args) | ||
{ | ||
LogListenerParser parser = listener.Parser; | ||
if (parser == null) | ||
return true; | ||
|
||
return parser.ShouldLog(args, listener); | ||
} | ||
} | ||
} |
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
15 changes: 6 additions & 9 deletions
15
src/KissLog/Internal/NotifyListeners/NotifyOnMessageService.cs
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,35 @@ | ||
using KissLog.Internal; | ||
using System.Collections.Generic; | ||
|
||
namespace KissLog | ||
{ | ||
public class ListenersContainer | ||
{ | ||
private readonly List<LogListenerDecorator> _listeners; | ||
public ListenersContainer() | ||
{ | ||
_listeners = new List<LogListenerDecorator>(); | ||
} | ||
|
||
public void Add(ILogListener listener) | ||
{ | ||
if (listener == null) | ||
return; | ||
|
||
var decorator = new LogListenerDecorator(listener); | ||
_listeners.Add(decorator); | ||
} | ||
|
||
internal IList<LogListenerDecorator> Get() | ||
{ | ||
List<LogListenerDecorator> result = new List<LogListenerDecorator>(); | ||
|
||
foreach(LogListenerDecorator decorator in _listeners) | ||
{ | ||
result.Add(decorator); | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
} |
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