-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Windows EventLog for NetStandard2.0 - new NLog.WindowsEventLog package #2547
Conversation
17f255b
to
d72434f
Compare
Codecov Report
@@ Coverage Diff @@
## master #2547 +/- ##
=======================================
- Coverage 81% 81% -<1%
=======================================
Files 326 326
Lines 24222 24242 +20
Branches 3068 3073 +5
=======================================
- Hits 19621 19604 -17
- Misses 3773 3809 +36
- Partials 828 829 +1 |
nice! I think this should be in NLog 5? |
It is a seperate Nuget-package, not dependent on any specific version of NLog. |
Think people doing NetCore optimized web-applications on the Windows-Platform would love to have this feature. |
Yes, great feature! |
src/NLog/Targets/Target.cs
Outdated
@@ -669,6 +669,9 @@ protected void MergeEventProperties(LogEventInfo logEvent) | |||
/// <returns>String representing log event.</returns> | |||
protected string RenderLogEvent(Layout layout, LogEventInfo logEvent) | |||
{ | |||
if (layout == null || logEvent == null) | |||
return string.Empty; |
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 think it would be nice to write a warning (maybe debug level) to the internal logger in this case, what do you think?
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.
Not sure I like messages per logevent.
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.
true, but not logging anything without any logs is also not that nice. Internal log Trace level otherwise?
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.
Well some Layouts are expected to be blank/null, so I think the important layout logging should be handled by the individual targets.
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, thanks for the input
src/NLog/Targets/EventLogTarget.cs
Outdated
@@ -437,11 +448,10 @@ private void CreateEventSourceIfNeeded(string fixedSource, bool alwaysThrowError | |||
catch (Exception exception) | |||
{ | |||
InternalLogger.Error(exception, "Error when connecting to EventLog."); | |||
if (alwaysThrowError || exception.MustBeRethrown()) | |||
if (alwaysThrowError || LogManager.ThrowExceptions) |
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.
this is a bugfix?
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.
Not public
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.
also this one, copy code or it should be public
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.
Don't like to pollute with public extension methods on non-NLog-objects. Have now introduced a new public method LogManager.MustBeRethrown(Exception)
src/NLog/Targets/EventLogTarget.cs
Outdated
var value = RenderLogEvent(EntryType, logEvent); | ||
|
||
EventLogEntryType eventLogEntryType; | ||
#if NETSTANDARD2_0 | ||
if (Enum.TryParse(value, true, out eventLogEntryType)) |
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.
could we move this to the EnumHelpers?
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.
Not public
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.
the line below there is the EnumHelpers? ;)
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.
The NetStandard2.0 EventLog-assembly is not part of the Nlog.dll, it is a separate package and cannot access internal stuff (unless I open for it like with unit-tests).
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.
cannot access internal stuff (unless I open for it like with unit-tests).
Maybe that isn't a bad idea, what do you think? Never done that with "public" assemblies, but guess it works?
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 don't like replacing a hack with another hack. The correct solution would be to make an official API. But I can copy-paste the code for this. Though code-search in the solution is going to be funny.
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, please copy-paste then for these cases, thx!
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.
Now performed copy-paste
src/NLog/Targets/EventLogTarget.cs
Outdated
|
||
|
||
short category = 0; | ||
if (!string.IsNullOrEmpty(renderCategory) && !short.TryParse(renderCategory, NumberStyles.Integer, CultureInfo.InvariantCulture, out category)) |
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.
why did we remove the RenderShort
and RenderInt?
Because there aren't public?
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.
Yes not public
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.
Proposal: or make public, or duplicate the code into this package :)
It's easier to maintain then
please share your thoughts
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 was thinking everything would be changed, when NLog 6.0 comes and explodes everything into smaller pieces. This PR is actually a small sample of the challenges that will come when the bomb explodes.
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.
yep, and it's easier to structural fix it with NLog 6 if we copy-paste now the methods, agree?
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.
Have now replaced internal LayoutHelpers with public ConversionHelpers.
39edcd4
to
a609d88
Compare
src/NLog/Common/ConversionHelpers.cs
Outdated
/// <param name="resultValue">Output value</param> | ||
/// <param name="defaultValue">Default value</param> | ||
/// <returns>Returns failure if the input value could not be parsed</returns> | ||
public static bool TryParseInt16(string inputValue, out short resultValue, short defaultValue = default(short)) |
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.
is there a reason why we use int16 etc, while short is recommend by MS?
src/NLog/Common/ConversionHelpers.cs
Outdated
/// <summary> | ||
/// String Conversion Helpers | ||
/// </summary> | ||
public static class ConversionHelpers |
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.
any idea why this isn't a git rename?
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.
probable because it was render...
and now tryparse...
Could you explain why this is changed? IMO the render...
was nice, also all rendering and conversing (and internal logging) would be handled consistently.
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.
Think the target should decide if critical error and if logging is needed
Imo Consistent internal logging is also important The helpers should help and make rendering easier, including error handling. In this pr they are tryparse wrappers. |
I prefer the flexibility. What if the input doesn't come from a Layout and LogEventInfo ? What if needing to log multiple parameters when conversion fails?
|
That's also possible, by not using the render helpers. Also that's not the case here? I have introduced the helpers because internal logging was forgotten and that gives too less insights when something when wrong. I propose to copy paste the current internal helpers, and keep them internal. In the future we could discuss a public API in which we are both happy with :) |
f3d6db7
to
1490f3b
Compare
This feature will be really useful. I'm wondering if this Nuget package will enable the EventLog target even if using NLog with ASP.NET Core (ie calling the ILoggingBuilder.UseNLog() in Program.cs)? Thank you for your work. |
Yes, but it's Windows only. |
I will release this hopefully today! |
merged! |
@vlef Has been released: https://www.nuget.org/packages/NLog.WindowsEventLog/ |
Great, thanks guys. However, I keep getting "Target cannot be found: 'EventLog'" when it's parsing my nuget.config. Is there anything else I should be doing other than adding the new nuget package NLog.WindowsEventLog to the project? |
Must run netcore2. But maybe you need <?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<extensions>
<add assembly="NLog.WindowsEventLog" />
</extensions>
<targets> |
Adding that extension in the config got me past the Target cannot be found error...but now I keep getting: 2018-05-29 08:53:26.7090 Trace AsyncWrapper(Name=eventlog): Writing 1 events (Timer) I updated NLog to 4.5.5. Any help is appreciated... |
The This means the current package can not work. We'd need an NLog 4.5.6 from the current master to fix that problem. |
@304NotModified & @idurston & @danstur Yes this PR was merged AFTER the NLog 4.5.5 release-cut (for some reason). I guess it needs to be re-releasesd with dependency on NLog 4.5.6 (And the NLog.WindowsEventLog 4.5.5 should be unlisted) |
I think I have to release all (NLog and this package) under 4.5.6, isn't? |
PS: I've unlisted the current package. |
Could you delay the NLog 4.5.6 some hours ? as I would like to fix a bug in JsonLayout
…Sent from my Samsung device
-------- Original message --------
From: Julian Verdurmen <notifications@github.com>
Date: 29/05/2018 17:21 (GMT+01:00)
To: NLog/NLog <NLog@noreply.github.com>
Cc: Rolf Kristensen <sweaty1@hotmail.com>, Mention <mention@noreply.github.com>
Subject: Re: [NLog/NLog] Windows EventLog for NetStandard2.0 - new NLog.WindowsEventLog package (#2547)
I think I have to release all (NLog and this package) under 4.5.6, ins;t?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#2547 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AK-fnPwcb7389oINpMuqwFIwOPyyXs44ks5t3WdygaJpZM4RvC7A>.
|
OK! |
@304NotModified Have now created #2747 |
4.5.6 is now on nuget.org: https://www.nuget.org/packages/NLog.WindowsEventLog (currently indexing on nuget.org) also a RTM of the dependency is released this evening: (that will be in 4.5.7) |
I can confirm that using the 4.5.6 NuGets solves the problem. |
@danstur Thanks for the confirmation! |
Depending on preview/pre-release nuget-package:
https://www.nuget.org/packages/System.Diagnostics.EventLog/
Expecting to be part of the NetCore compatibility pack:
https://blogs.msdn.microsoft.com/dotnet/2017/11/16/announcing-the-windows-compatibility-pack-for-net-core/