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

Log unused targets to internal logger #1084

Merged

Conversation

UgurAldanmaz
Copy link
Contributor

Closes #1074

InternalLogger.Warn("Unused target checking is started... Rule Count: {0}, Target Count: {1}", this.LoggingRules.Count, configuredNamedTargets.Count);

HashSet<string> targetNamesAtRules = new HashSet<string>();
for (int ri = 0; ri < this.LoggingRules.Count; ri++)
Copy link
Member

Choose a reason for hiding this comment

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

Looks good, but we can also use easily LINQ here?

Something like (code not checked)

 HashSet<string> targetNamesAtRules = new HashSet<string>(this.LoggingRules.SelectMany(r => r.Target).Select(t => t.Name));

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.

It is possible. Maybe I was a bit obsessive about performance, therefore I have used the classic ways.

Copy link
Member

Choose a reason for hiding this comment

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

Yes it's true that the for is somewhat better in performance. But luckily this code is only run when the config changes.

Copy link
Member

Choose a reason for hiding this comment

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

You can measure the difference with your stopwatch ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahaha. Unfortunately I removed my stopwatch :P

OK. Linq way would be more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To support under version of .Net 3.5, we should not use LINQ. Also Mono.

But it seems we have solution files for 3.5 and newer.

Copy link
Member

Choose a reason for hiding this comment

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

Hey! Linq is supported, we already use it (and I cannot live without it, I like functional programming)

Are you confused with linq-to-sql?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I am not confused with linq-to-sql.

To be sure whether Linq will broke something, I searched which version has support. Maybe my conclusion is wrong. But I could not found any result for supporting older than .Net 3.5 (without extra effort)
At least Linq MSDN page has not older version.

@304NotModified
Copy link
Member

Thanks! Looks really nice!

PS: AppVeyor complains about stopwatch. As the current datetime is logged with the internallogger, I think stopwatch isn't needed.

@304NotModified 304NotModified added enhancement Improvement on existing feature feature labels Dec 9, 2015
InternalLogger.Warn("Unused target checking is canceled -> initialize not started yet.");
return;
}
if (this.InitializeSucceeded.Value == false)
Copy link
Member

Choose a reason for hiding this comment

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

We prefer if (!this.InitializeSucceeded.Value). (just code style)

@304NotModified 304NotModified changed the title Log unused targets to internal logger (Closes #1074) Log unused targets to internal logger Dec 9, 2015
@304NotModified 304NotModified added this to the 4.3 milestone Dec 9, 2015
@codecov-io
Copy link

Current coverage is 72.92%

Merging #1084 into master will decrease coverage by -0.12% as of d4a79ea

@@            master   #1084   diff @@
======================================
  Files          263     263       
  Stmts        14901   14925    +24
  Branches      1623    1627     +4
  Methods          0       0       
======================================
- Hit          10885   10884     -1
  Partial        418     418       
- Missed        3598    3623    +25

Review entire Coverage Diff as of d4a79ea


Uncovered Suggestions

  1. +0.09% via ...nternal/AspHelper.cs#206...218
  2. +0.09% via ...nternal/AspHelper.cs#188...200
  3. +0.09% via ...nternal/AspHelper.cs#170...182
  4. See 7 more...

Powered by Codecov. Updated on successful CI builds.

@UgurAldanmaz UgurAldanmaz self-assigned this Dec 9, 2015
Uğur Aldanmaz added 2 commits December 13, 2015 12:51
Comment about ConfiguredNamedTargets was not clear.
304NotModified added a commit that referenced this pull request Dec 13, 2015
…rnal-logger

Log unused targets to internal logger
@304NotModified 304NotModified merged commit 6947311 into NLog:master Dec 13, 2015
@304NotModified
Copy link
Member

Merged! Thanks! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement on existing feature feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants