Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Logging Rule with FinalMinLevel also supports dynamic filters - #5489

#5489
Merged
snakefoot merged 1 commit into
NLog:devNLog/NLog:devfrom
snakefoot:sourcenamesnakefoot/NLog:sourcenameCopy head branch name to clipboard
Mar 29, 2024
Merged

Logging Rule with FinalMinLevel also supports dynamic filters#5489
snakefoot merged 1 commit into
NLog:devNLog/NLog:devfrom
snakefoot:sourcenamesnakefoot/NLog:sourcenameCopy head branch name to clipboard

Conversation

@snakefoot

@snakefoot snakefoot commented Mar 28, 2024

Copy link
Copy Markdown
Contributor

Ensure that dynamic filters also applies for logging-rules with FinalMinLevel and no targets:

<nlog throwConfigExceptions="true" internalLogToConsole="true" internalLogLevel="Debug">
  <targets>
    <target type="ColoredConsole"
            name="lifetimeConsole"
            layout="${date:format=yyyy-MM-dd HH\:mm\:ss zzz} [${level:uppercase=true}] [${logger}] ${message} ${exception:format=tostring}" />

  </targets>
  <rules>
    <logger name="System.*" finalMinLevel="Warn" />
    <logger name="System.Net.Http.*" finalMinLevel="Warn" />
    <logger name="Microsoft.*" finalMinLevel="Warn" />
    <logger name="Microsoft.Hosting.Lifetime" finalMinLevel="Info" />
    <logger name="Microsoft.EntityFrameworkCore.*" finalMinLevel="Info" />
    <logger name="Microsoft.EntityFrameworkCore.Database.Command" finalMinLevel="Info">
      <filters defaultAction="Log">
        <when condition="contains('${message}','Executed DbCommand')" action="IgnoreFinal" />
      </filters>
    </logger>
    <logger name="*" minlevel="Info" writeTo="lifetimeConsole" />
  </rules>
</nlog>

See also #5488

@snakefoot snakefoot added the enhancement Improvement on existing feature label Mar 28, 2024
@sonarqubecloud

Copy link
Copy Markdown

@snakefoot
snakefoot merged commit 22f94f3 into NLog:dev Mar 29, 2024
@snakefoot snakefoot added this to the 5.3.0 milestone Mar 30, 2024
@snakefoot snakefoot changed the title Logging Rule with FinalMinLevel should also support dynamic filters Logging Rule with FinalMinLevel also supports dynamic filters Mar 30, 2024
finalMinLevelWithFilters = finalMinLevelWithFilters ?? new KeyValuePair<FilterResult?, IList<Filter>>[LogLevel.MaxLevel.Ordinal + 1];
for (int i = 0; i <= LogLevel.MaxLevel.Ordinal; ++i)
{
if (i < rule.FinalMinLevel.Ordinal)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In other places in the codebase FinalMinLevel is either guarded for null or there are prevention to set it to null but it's default appears to be null. When testing 5.3.1 in our codebase (to update) we encountered a rule with a FinalMinLevel unset (null) that causes a null reference to be thrown here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for reporting this. I have been able to reproduce the NullReferenceException by creating a LoggingRule with filters but without targets. Will try get a fix out ASAP.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@BooTeK NLog v5.3.2 has now been released - https://www.nuget.org/packages/NLog/5.3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement on existing feature size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.