-
Notifications
You must be signed in to change notification settings - Fork 23
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
Support for mixed parameters and/or TimeSpan parsing #9
Comments
Thanks for the note. Just on item #1, I don't think The second point is a pretty deep part of the design of this package; one thing we could do here is let |
For the timespan parsing, I would say it's wrong to accept ms as a unit by default. FYI the
And So I would say that we should accept values that are valid strings for For the second point <add key="serilog:enrich:with-property:MachineName" value="%COMPUTERNAME%" />
Maybe adding an overload of You would then pass for instance
and <add key="serilog:enrich:with-property:MachineName" value="%COMPUTERNAME%" />
<add key="serilog:enrich:with-property:Foo" value="%FOO%" />
<add key="serilog:enrich:with-property:Baz" value="%BAZ%" /> and stuff between the Would that cover this use case ? |
+1 on supporting the syntax understood by The variable substitution puzzle is getting interesting :-) Just to put one other idea out there, already discussed in the #7 level switch thread: <add key="serilog:enrich:with-property:Foo" value="$foo" /> where: new Dictionary<string, object>{
{"foo", 42},
{"bar", "qux"},
} I.e., instead of string substitution, we could implement object references. The litmus test would be whether it'd work seamlessly with: var ls = new LoggingLevelSwitch(LogEventLevel.Information);
Log.Logger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(ls)
.ReadFrom.Configuration(new Dictionary<string, object>{
["ls"] = ls
})
.CreateLogger(); With config containing: <add key="serilog:write-to:Seq.controlLevelSwitch" value="$ls" /> It's dangerous designing these kinds of things piecemeal, but it would also be nice if we could fit multiple features cleanly into the one simple "variables" framework. (Against this style we might consider the argument that pushing variables down from the code into the config is almost the reverse of Serilog's typically code-first design - although we've failed to come up with a code-centric solution to the mixed/overridden configuration requirement so far.) |
@JFesta Regarding According to MSDN :
So the proper way to write, say, 30 seconds, is It is not officially documented in Serilog, but I've just issued a PR (serilog/serilog#1030) with passing tests like this : [Theory]
[InlineData("3.14:21:18.986", 3 /*days*/, 14 /*hours*/, 21 /*min*/, 18 /*sec*/, 986 /*ms*/)]
[InlineData("4", 4, 0, 0, 0, 0)] // minimal : days
[InlineData("2:0", 0, 2, 0, 0, 0)] // minimal hours
[InlineData("0:5", 0, 0, 5, 0, 0)] // minimal minutes
[InlineData("0:0:7", 0, 0, 0, 7, 0)] // minimal seconds
[InlineData("0:0:0.2", 0, 0, 0, 0, 200)] // minimal milliseconds
public void TimeSpanValuesCanBeParsed(string input, int expDays, int expHours, int expMin, int expSec, int expMs)
{
var expectedTimeSpan = new TimeSpan(expDays, expHours, expMin, expSec, expMs);
var actual = SettingValueConversions.ConvertToType(input, typeof(TimeSpan));
Assert.IsType<TimeSpan>(actual);
Assert.Equal(expectedTimeSpan, actual);
} |
@JFesta regarding
would proposal serilog/serilog#1038 help ? |
Closing this one for now.
Can be reopened if needed :) |
In my application I want to write my logs using Serilog.Sinks.RollingFile. Additionally, as I need to configure some things (e.g. the pathFormat or the minimum logging level) depending on what environment I'm deploying it, I tried to use Serilog.Settings.AppSettings to read parameters from App.config.
Everything was working fine, until I had to use RollingFile's parameter flushToDiskInterval, which happens to be a TimeSpan.
I added a new setting that was like:
<add key="serilog:write-to:RollingFile.flushToDiskInterval" value="10000" />
Guessing that the value would be parsed as a time in milliseconds. It didn't work as Serilog, fairly enough, throws an exception when trying to parse the parameter.
I didn't find in the internet if and how TimeSpans are handled. Are they even implemented? It could be very useful.
This brings to another problem. I thought that I could just use ReadFrom.AppSettings() to get what I need from App.config, and modify some other parameter afterwards, like the already mentioned flushToDiskInterval. Generally speaking, I wanted to load some parameters from App.config and some others programmatically.
Problem is, I didn't found any way to access those parameters, or even the logger itself, after it has been created through Read.FromAppSettings().
This forced me to stop using Serilog.Settings.AppSettings and to implement my own logic: now I read all the needed parameters programmatically from App.Config manually, and it's not a good solution:
config.WriteTo.RollingFile( System.Configuration.ConfigurationManager.AppSettings["serilog:write-to:RollingFile.pathFormat"], ... );
It would be awesome to have at least one of these two features:
I'm assuming both features are not yet implemented as I didn't found them, but I would be happy to know how to use them if they are already implemented, as I failed to find anything on the internet.
The text was updated successfully, but these errors were encountered: