Skip to content

KeyValuePairSettings : support for static members via :: #1057

@tsimbalar

Description

@tsimbalar

Related to discussion going on in serilog/serilog-sinks-console#16

It would be nice to support static members for configuration methods that accept a complex type .

The typical use case is Serilog.Sinks.Console with its configuration method :

public static LoggerConfiguration Console(
	this LoggerSinkConfiguration sinkConfiguration,
	LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
	string outputTemplate = DefaultConsoleOutputTemplate,
	IFormatProvider formatProvider = null,
	LoggingLevelSwitch levelSwitch = null,
	LogEventLevel? standardErrorFromLevel = null,
	ConsoleTheme theme = null)

where ConsoleTheme is an abstract class, but static members exist (ConsoleTheme.None, SystemConsoleTheme.Literate, AnsiConsoleTheme.Grayscale etc )

One possible syntax that would be do access static members via :: (like in Powershell or PHP), for instance

<configuration>
  <appSettings>
    <add key="serilog:using:Console" value="Serilog.Sinks.Console" />
    <add key="serilog:write-to:Console.theme" value="Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Grayscale, Serilog.Sinks.Console" />

would use static property Grayscale of type Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme in assembly Serilog.Sinks.Console.

As in #1056 the idea is that we should be able to specify the minimum information about the type to make the configuration less verbose (for instance, no need for the assembly name, Version, PublicKeyToken etc if we can avoid it).

Other use-case where this would help : Serilog.Sinks.Email that accepts a EmailConnectionInfo for advanced configuration

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions