Skip to content

Don't know how to configure alternate theme in appsettings.json #53

@chriswolf-nrg

Description

@chriswolf-nrg

Does this issue relate to a new feature or an existing bug?

  • [ x] Bug
  • New Feature

What version of Serilog Console Sink is affected by this issue? Please list the related NuGet package.
Serilog 2.6.0
Serilog.Sinks.Console 3.1.1
What is the target framework and operating system affected by this issue? Please see target frameworks & net standard matrix.

  • netCore 2.1
  • netCore 2.0
  • netCore 1.0
  • 4.7
  • 4.6.x
  • 4.5.x

Please describe the current behaviour you are experiencing?
Don't know how to configure alternate theme in appsettings.json

This is a documentation issue. There is insufficient documentation on how to change themes via the appsettings.json. Near the beginning of the README.md document are listed some theme names: ConsoleTheme.None, SystemConsoleTheme.Literate, SystemConsoleTheme.Grayscale, etc.

However, later when an example JSON configuration is given, none of the above names are used, instead, the example is as follows:

"theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console",

Ok, so I'm supposed to prefix the theme name with Serilog.Sinks.SystemConsole.Themes and change the . in the theme name to :: (I guess... - this name mangling is not mentioned in the README.md) Now I want all colors to be suppressed, which I assume is what the theme named ConsoleTheme.None does. So I put this in my configuration:

  "WriteTo": [
      { "Name": "Console",
        "Args": {
            "theme": "Serilog.Sinks.SystemConsole.Theme.ConsoleTheme::None, Serilog.Sinks.Console"
        }
      },

And here's the output from my console app:

Unhandled Exception: System.InvalidCastException: Invalid cast from 'System.String' to 'Serilog.Sinks.SystemConsole.Themes.ConsoleTheme'.
   at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
   at Serilog.Settings.Configuration.StringArgumentValue.ConvertTo(Type toType)
   at Serilog.Settings.Configuration.ConfigurationReader.<>c.<CallConfigurationMethods>b__14_4(<>f__AnonymousType6`2 <>h__TransparentIdentifier0)
   at System.Linq.Utilities.<>c__DisplayClass2_0`3.<CombineSelectors>b__0(TSource x)
   at System.Linq.Enumerable.SelectListPartitionIterator`2.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Serilog.Settings.Configuration.ConfigurationReader.CallConfigurationMethods(ILookup`2 methods, IList`1 configurationMethods, Object receiver)
   at Serilog.Configuration.LoggerSettingsConfiguration.Settings(ILoggerSettings settings)

I already read #16 and that didn't help me. Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions