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

Add support for LoggingLevelSwitch #88

Merged
merged 2 commits into from
Feb 13, 2018

Conversation

tsimbalar
Copy link
Member

fixes #69

Supports :

  • declaration of LoggingLevelSwitch
  • MinimumLevel.ControlledBy(switch)
  • MinimumLevel.Override(prefix, switch)
  • passing a switch by reference as the argument to a Sink (or any callable method)

JSON syntax :

{
  "Serilog": {
    "Using": [ "TestDummies" ],
    "LevelSwitches": { "$mySwitch": "Warning" },
    "MinimumLevel": {
      "ControlledBy": "$mySwitch"
    },
    "WriteTo": [
      {
        "Name": "DummyWithLevelSwitch",
        "Args": {
          "controlLevelSwitch": "$mySwitch"
        }
      }
    ]
  }
}

but also overrides :

{
  "Serilog": {
    "Using": [ "TestDummies" ],
    "LevelSwitches": { "$mySwitch": "Warning" },
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "$mySwitch"
      }
    },
    "WriteTo": [
      {
        "Name": "DummyWithLevelSwitch",
        "Args": {
          "controlLevelSwitch": "$mySwitch"
        }
      }
    ]
  }
}

In order to implement "look up a switch by name", I had to change IConfigurationArgumentValue's method object ConvertTo(Type toType) to object ConvertTo(Type toType, IReadOnlyDictionary<string, LoggingLevelSwitch> declaredLevelSwitches) and cascade that change everywhere ...

ApplyAuditSinks(loggerConfiguration, declaredLevelSwitches);
}

private IReadOnlyDictionary<string, LoggingLevelSwitch> ProcessLevelSwitchDeclarations()
Copy link
Member

Choose a reason for hiding this comment

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

Very minor nitpick- the Serilog repos don't use explicit private or internal (I think there might be a DotSettings file in the main repo.)

Copy link
Member Author

Choose a reason for hiding this comment

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

yes indeed :) I'll copy over the .DotSettings file from the main repo to detect those cases.

@nblumhardt
Copy link
Member

Looks awesome 👍

Just added one minor nitpick - keen to get this to dev so we can kick the tires! :-)

Thibaud DESODT added 2 commits February 13, 2018 08:28
solves serilog#69
Supports : 
- declaration of LoggingLevelSwitch 
- MinimumLevel.ControlledBy(switch)
- MinimumLevel.Override(prefix, switch)
- passing a switch by reference as the argument to a Sink (or any callable method)
Copy over .editorconfig and .sln.DotSettings from core repo
Fix ReSharper red squigglies
Fix remaining ReSharper warnings (possible multiple enumeration)
Remove implicit "private" keywords
@tsimbalar tsimbalar force-pushed the loglevelswitchsupport branch from 12702d1 to 7034ca6 Compare February 13, 2018 07:28
@tsimbalar
Copy link
Member Author

I've updated the code based on your comments :)

@nblumhardt nblumhardt merged commit af9efd3 into serilog:dev Feb 13, 2018
@nblumhardt
Copy link
Member

🎉

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.

LoggingLevelSwitch support
2 participants