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

issue #22 - added capability to provide known event id's based off log events #23

Merged
merged 3 commits into from
Nov 20, 2017
Merged

Conversation

mrbcmorris
Copy link
Member

Just wanted to get the ball rolling for issue# 22 with a sample implementation.

Copy link
Member

@nblumhardt nblumhardt left a comment

Choose a reason for hiding this comment

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

Looks great! Just a couple of thoughts; @GavinSutherland how does this match up to your expectations?

/// </summary>
/// <param name="logEvent">The log event to compute the event id from.</param>
/// <returns>Computed event id based off the given log.</returns>
ushort Compute(LogEvent logEvent);
Copy link
Member

Choose a reason for hiding this comment

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

Could be ComputeEventId?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. Commit pushed.

{
if (loggerConfiguration == null) throw new ArgumentNullException(nameof(loggerConfiguration));

var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);

return loggerConfiguration.Sink(new EventLogSink(source, logName, formatter, machineName, manageEventSource), restrictedToMinimumLevel);
return loggerConfiguration.Sink(new EventLogSink(source, logName, formatter, machineName, manageEventSource, eventIdProvider), restrictedToMinimumLevel);
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps this is where we do the ?? new EventIdHashProvider(), so that EventLogSink can require a non-null IEventIdProvider argument?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that would be cleaner as it keeps configuration in LoggerConfigurationEventLogExtensions and it makes the EventLogSink more transparent on behavior. My only concern is introducing a new required parameter on the existing EventLogSink constructor. Is this something we should be concerned with? If so, I could make this change as requested and add a constructor overload for EventLogSink to support a custom IEventIdProvider.

Let me know what you think.

Copy link
Member

Choose a reason for hiding this comment

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

Overloaded constructor sounds like it would be a winner 👍

Choose a reason for hiding this comment

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

I like the idea of an overloaded constructor on EventLogSink to allow us to pass in a non-null IEventIdProvider.

Copy link
Member Author

@mrbcmorris mrbcmorris Nov 20, 2017

Choose a reason for hiding this comment

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

added overloaded constructor to EventLogSink. Attempting to keep default value for IEventIdProvider in one location so I've made the more generic constructor call the more complex constructor with the default value and have LoggerConfigurationEventLogExtensions smart enough to determine which constructor to utilize.

@GavinSutherland
Copy link

Hi @nblumhardt, @mrbcmorris

Yeah this looks good and meets my requirements. Other than creating the overloaded EventLog constructor as Nicholas suggested I think it's good to go.

Thanks Chris!

Copy link

@GavinSutherland GavinSutherland left a comment

Choose a reason for hiding this comment

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

Minor documentation changes required in LoggerConfigurationEventLogExtensions.cs

@@ -68,6 +70,7 @@ public static class LoggerConfigurationEventLogExtensions
/// <param name="manageEventSource">If false does not check/create event source. Defaults to true i.e. allow sink to manage event source creation</param>
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
/// <param name="formatter">Formatter to control how events are rendered into the file. To control
/// <param name="eventIdProvider">Supplies event ids for emitted log events.</param>

Choose a reason for hiding this comment

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

The eventIdProvider param documentation has been inserted in the middle of the formatter param documentation.

Fixed documentaiton in LoggerConfigurationEventLogExtensions

Updated LoggerConfigurationEventLogExtensions to honor the constructor overload
@nblumhardt nblumhardt merged commit 931b67b into serilog:dev Nov 20, 2017
@nblumhardt
Copy link
Member

👍 thanks @mrbcmorris !

@nblumhardt
Copy link
Member

Odd, looks like CI somehow skipped the last commit - missing file: https://ci.appveyor.com/project/serilog/serilog-sinks-eventlog/build/46

@mrbcmorris do you have the missing appsettings.xml file handy? :-) Cheers!

@mrbcmorris
Copy link
Member Author

@nblumhardt interesting...it looks like the file is still here.

Digging in a bit more, i was surprised to see the particular test in question using Directory.GetCurrentDirectory() . My understanding of this would be that the tests pass or fail based off the location dotnet test was invoked from.

Generally I've relied on AppDomain.CurrentDomain.BaseDirectory to help me locate any content I need during test runtime. I've made the change locally and confirmed the test is successful via IDE and running dotnet test. I'm not familiar with the build powershell script so I don't know how to appropraitely test it.

I still don't understand how this test was passing previous to this PR.

Thoughts on how to move forward?

@nblumhardt
Copy link
Member

@mrbcmorris thanks for the follow-up; I think AppDomain.CurrentDomain.BaseDirectory has done the trick 👍

I'd guess some change to the build image will have been responsible. New -dev package should be out soon, @GavinSutherland.

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.

3 participants