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

Windows EventLog for NetStandard2.0 - new NLog.WindowsEventLog package #2547

Merged
merged 3 commits into from
May 25, 2018

Conversation

snakefoot
Copy link
Contributor

@snakefoot snakefoot commented Jan 27, 2018

@snakefoot snakefoot force-pushed the NetCoreEventLog branch 7 times, most recently from 17f255b to d72434f Compare January 27, 2018 11:30
@codecov
Copy link

codecov bot commented Jan 27, 2018

Codecov Report

Merging #2547 into master will decrease coverage by <1%.
The diff coverage is 50%.

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

@304NotModified 304NotModified added this to the 5.0 (new) milestone Jan 28, 2018
@304NotModified
Copy link
Member

nice!

I think this should be in NLog 5?

@snakefoot
Copy link
Contributor Author

I think this should be in NLog 5?

It is a seperate Nuget-package, not dependent on any specific version of NLog.

@snakefoot
Copy link
Contributor Author

snakefoot commented Jan 29, 2018

Think people doing NetCore optimized web-applications on the Windows-Platform would love to have this feature.

@304NotModified
Copy link
Member

Yes, great feature!

@@ -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;
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

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

this is a bugfix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not public

Copy link
Member

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

Copy link
Contributor Author

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)

var value = RenderLogEvent(EntryType, logEvent);

EventLogEntryType eventLogEntryType;
#if NETSTANDARD2_0
if (Enum.TryParse(value, true, out eventLogEntryType))
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not public

Copy link
Member

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? ;)

Copy link
Contributor Author

@snakefoot snakefoot Feb 6, 2018

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).

Copy link
Member

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?

Copy link
Contributor Author

@snakefoot snakefoot Feb 6, 2018

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.

Copy link
Member

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now performed copy-paste



short category = 0;
if (!string.IsNullOrEmpty(renderCategory) && !short.TryParse(renderCategory, NumberStyles.Integer, CultureInfo.InvariantCulture, out category))
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes not public

Copy link
Member

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

Copy link
Contributor Author

@snakefoot snakefoot Feb 6, 2018

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.

Copy link
Member

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?

Copy link
Contributor Author

@snakefoot snakefoot Feb 6, 2018

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.

@304NotModified
Copy link
Member

Meta data Looks good :)

image

@304NotModified 304NotModified modified the milestones: 5.0 (new), 4.5 Feb 6, 2018
@snakefoot snakefoot force-pushed the NetCoreEventLog branch 2 times, most recently from 39edcd4 to a609d88 Compare February 6, 2018 21:22
/// <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))
Copy link
Member

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?

/// <summary>
/// String Conversion Helpers
/// </summary>
public static class ConversionHelpers
Copy link
Member

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?

Copy link
Member

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.

Copy link
Contributor Author

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

@304NotModified
Copy link
Member

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.

@snakefoot
Copy link
Contributor Author

snakefoot commented Feb 12, 2018 via email

@304NotModified
Copy link
Member

I prefer the flexibility.

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 :)

@ghost
Copy link

ghost commented May 24, 2018

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.

@304NotModified
Copy link
Member

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

Yes, but it's Windows only.

@304NotModified
Copy link
Member

I will release this hopefully today!

@304NotModified 304NotModified merged commit cc6e653 into NLog:master May 25, 2018
@304NotModified
Copy link
Member

merged!

@snakefoot
Copy link
Contributor Author

@vlef Has been released: https://www.nuget.org/packages/NLog.WindowsEventLog/

@ghost
Copy link

ghost commented May 25, 2018

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?

@snakefoot
Copy link
Contributor Author

Must run netcore2. But maybe you need add assembly at the top of your NLog.config:

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

@idurston
Copy link

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)
2018-05-29 08:53:26.7090 Trace AsyncWrapper(Name=webservice): Writing 1 events (Timer)
2018-05-29 08:53:26.9850 Error Error has been raised. Exception: System.TypeLoadException: Could not load type 'NLog.Common.ConversionHelpers' from assembly 'NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c'.
at NLog.Targets.EventLogTarget.GetEntryType(LogEventInfo logEvent)
at NLog.Targets.EventLogTarget.Write(LogEventInfo logEvent)
at NLog.Targets.Target.Write(AsyncLogEventInfo logEvent)

I updated NLog to 4.5.5. Any help is appreciated...

@danstur
Copy link

danstur commented May 29, 2018

The NLog.Common.ConversionHelpers is not part of the released NLog 4.5.5 nuget package, the class is still NLog.Internal.EnumHelpers in the released sources.

This means the current package can not work. We'd need an NLog 4.5.6 from the current master to fix that problem.

@snakefoot
Copy link
Contributor Author

snakefoot commented May 29, 2018

@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)

@304NotModified
Copy link
Member

304NotModified commented May 29, 2018

I think I have to release all (NLog and this package) under 4.5.6, isn't?

@304NotModified
Copy link
Member

PS: I've unlisted the current package.

@snakefoot
Copy link
Contributor Author

snakefoot commented May 29, 2018 via email

@304NotModified
Copy link
Member

OK!

@304NotModified 304NotModified mentioned this pull request May 29, 2018
3 tasks
@snakefoot
Copy link
Contributor Author

@304NotModified Have now created #2747

@304NotModified
Copy link
Member

304NotModified commented May 29, 2018

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)

image

@danstur
Copy link

danstur commented May 30, 2018

I can confirm that using the 4.5.6 NuGets solves the problem.

@304NotModified 304NotModified modified the milestones: 4.5, 4.5.6 May 30, 2018
@304NotModified
Copy link
Member

@danstur Thanks for the confirmation!

@snakefoot snakefoot mentioned this pull request Aug 15, 2018
5 tasks
@snakefoot snakefoot deleted the NetCoreEventLog branch April 4, 2020 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants