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

Provide example of Interface/Abstract class with values #1

Open
Alxandr opened this issue Mar 7, 2019 · 4 comments
Open

Provide example of Interface/Abstract class with values #1

Alxandr opened this issue Mar 7, 2019 · 4 comments

Comments

@Alxandr
Copy link

Alxandr commented Mar 7, 2019

I'm trying to translate the following to config:

new JsonFormatter(renderMessage: true)

I came across this repo, and I imagine I can figure out how to do this, but it would be great if there was an example of this kind of value ready.

@tsimbalar
Copy link
Owner

Hi Aleksander ,

It is not supported right now in any of the Settings providers for Serilog right now, unfortunately (calling a constructor and passing parameters is not doable at the moment).

Some workarounds you can use :

using Serilog.Formatting;
namespace Serilog.SettingsComparisonTests.Support.Formatting
{
public static class CustomFormatters
{
public static ITextFormatter Formatter {get;} = new MyFormatter();
}
}

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="serilog:using:TestDummies" value="TestDummies" />
<add key="serilog:write-to:DummyWithFormatter.formatter" value="Serilog.SettingsComparisonTests.Support.Formatting.CustomFormatters::Formatter, Serilog.Settings.Comparison.Tests" />
<add key="serilog:write-to:DummyConsole.theme" value="TestDummies.Console.Themes.ConsoleThemes::Theme1, TestDummies" />
</appSettings>
</configuration>

or

{
"Serilog": {
"Using": [ "TestDummies" ],
"WriteTo": [
{
"Name": "DummyWithFormatter",
"Args": {
"formatter": "Serilog.SettingsComparisonTests.Support.Formatting.CustomFormatters::Formatter, Serilog.Settings.Comparison.Tests"
}
},
{
"Name": "DummyConsole",
"Args": {
"theme": "TestDummies.Console.Themes.ConsoleThemes::Theme1, TestDummies"
}
}
]
}
}

I hope this helps !

@Alxandr
Copy link
Author

Alxandr commented Mar 8, 2019

Bummer. Thanks for this info though :)

@tsimbalar
Copy link
Owner

I don't know if that's a common enough scenario to ask for the creation of some static properties in JsonFormatter in the core Serilog repo : JsonFormatter.WithRenderedMessage or something like that

public static ITextFormatter WithRenderedMessage {get;} = new JsonFormatter(renderMessage: true);

which would allow to use it directly in the settings providers with something like :

 <?xml version="1.0" encoding="utf-8"?> 
 <configuration> 
   <appSettings>
     <add key="serilog:write-to:DummyWithFormatter.formatter" value="Serilog.Formatting.Json.JsonFormatter::WithRenderedMessage, Serilog" /> 
   </appSettings> 
</configuration> 

@nblumhardt : would that make sense, or would that just add noise in the core repo ?

@Alxandr
Copy link
Author

Alxandr commented Mar 8, 2019

@tsimbalar Or provide a way to use constructors.

"formatter": {
  "@type": "Serilog.Formatting.Json.JsonFormatter",
  "renderMessage": true
}

This is basically the logic already used to allow doing DymmyWithFormatter.formatter already, just recursively.

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

No branches or pull requests

2 participants