-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ILogger input #18
ILogger input #18
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks very good
@@ -245,6 +245,48 @@ namespace SerilogEventFlow | |||
} | |||
``` | |||
|
|||
#### ILogger | |||
|
|||
*Nuget package:* **Microsoft.Diagnostics.EventFlow.Inputs.ILogger** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I is likely that a lot of different libraries will use the ILogger concept and define their own ILogger implementation. For example Serilog has one: https://github.com/serilog/serilog/blob/dev/src/Serilog/ILogger.cs
So I suggest that we name the package and the input so that it conveys it is about Microsoft.Extensions.Logging package and its implementation of ILogger. For example
Microsoft.Diagnostics.EventFlow.Inputs.MicrosoftLogging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, this name is very confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will rename to Microsoft.Diagnostics.EventFlow.Inputs.MicrosoftLogging
The ILogger input has no configuration, other than the "type" property that specifies the type of the input (must be "ILogger"): | ||
```json | ||
{ | ||
"type": "ILogger" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using "Microsoft.Extensions.Logging" as the input type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
using (var pipeline = DiagnosticPipelineFactory.CreatePipeline(".\\eventFlowConfig.json")) | ||
{ | ||
var factory = new LoggerFactory() | ||
.AddEventFlow(pipeline); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this. Very clean!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Internal; | ||
|
||
namespace Microsoft.Diagnostics.EventFlow.Inputs.ILogger.Logger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use just Microsoft.Diagnostics.EventFlow.Inputs namespace for all input code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(applies to other files too)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
|
||
public EventFlowLogger(string categoryName, LoggerInput loggerInput) | ||
{ | ||
Debug.Assert(categoryName != null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Validation.NotNull() for parameter checking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok (EventFlowLogger is internal, so it's not public API)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood, but even for internal types, I like to do parameter checking and throw if the checks fail. I like to think that public methods & properties form a contract with consumers and parameter checking is part of that contract. OK to just assert the correctness of parameters of private methods.
} | ||
else | ||
{ | ||
properties.Add("Scope", scope.State); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same concern about duplicate property names here
|
||
public bool IsEnabled(Extensions.Logging.LogLevel logLevel) | ||
{ | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Should we allow to drop events based on the level inside this Logger? Seems like a common requirement--during routine execution you probably want to capture only warnings or worse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Level based event filtering could be done without EventFlow when factory is being created:
factory
.WithFilter(new FilterLoggerSettings { { "ConsoleApp1.Program", LogLevel.Warning } })
.WithEventFlow();
If we additionally configure level-based filtering on EventFlow side it may conflict with MS.Extenstion.Logging approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, let's not have this extra configuration parameter
if (payload != null) | ||
{ | ||
foreach (var kv in payload) | ||
eventPayload.Add(kv); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the payload already has properties named "Message", "EventId", "EventName" etc?
} | ||
catch (Exception ex) | ||
{ | ||
this.healthReporter?.ReportProblem($"Failed to write message. Error: {ex}", TraceTag); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Health reporter will never be null (given constructor check)
- Reporting a warning is probably more appropriate
- Use ex.ToString() for extra clarity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will fix
@@ -0,0 +1,232 @@ | |||
using System; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job with the tests!!
return new AddResult(); | ||
} | ||
|
||
Random random = new Random(DateTime.Now.Millisecond); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- No need to use Random(seed) constructor; the parameter-less constructor does what your code does
- How about creating a static instance of the Random class and caching it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
One more thing: in Warsaw.sln make sure the new MicrosoftLogging project is listed as a dependency of the signing project |
This change implements ILogger input