Skip to content
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

Closed
wants to merge 4 commits into from
Closed

ILogger input #18

wants to merge 4 commits into from

Conversation

lmolkova
Copy link
Member

This change implements ILogger input

Copy link
Collaborator

@karolz-ms karolz-ms left a 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**
Copy link
Collaborator

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

Copy link

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.

Copy link
Member Author

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"
Copy link
Collaborator

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?

Copy link
Member Author

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);
Copy link
Collaborator

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!

Copy link
Member Author

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
Copy link
Collaborator

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

Copy link
Collaborator

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)

Copy link
Member Author

@lmolkova lmolkova Nov 17, 2016

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);
Copy link
Collaborator

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

Copy link
Member Author

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)

Copy link
Collaborator

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);
Copy link
Collaborator

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;
Copy link
Collaborator

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.

Copy link
Member Author

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.

Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Health reporter will never be null (given constructor check)
  2. Reporting a warning is probably more appropriate
  3. Use ex.ToString() for extra clarity

Copy link
Member Author

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;
Copy link
Collaborator

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!!

@lmolkova lmolkova mentioned this pull request Nov 18, 2016
return new AddResult();
}

Random random = new Random(DateTime.Now.Millisecond);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. No need to use Random(seed) constructor; the parameter-less constructor does what your code does
  2. How about creating a static instance of the Random class and caching it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@karolz-ms
Copy link
Collaborator

One more thing: in Warsaw.sln make sure the new MicrosoftLogging project is listed as a dependency of the signing project

@lmolkova lmolkova closed this Nov 21, 2016
@karolz-ms karolz-ms deleted the dev/lmolkova/ilogger branch April 18, 2017 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants