-
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
Dynamic Log Filenames #40
Comments
You can use environment variables in Serilog.Settings.AppSettings values, so if you call |
Thanks for your suggestion nblumhardt, this does seem like a possible solution. How about applications that are running in a context that are more confined and cannot set environmental variables. Or if you are using this as a logging class library. Each application using this would set its own environmental variable value to 'appname' and you would get in all kinds of mess. |
Thanks for the reply. The same kinds of issues apply to the log4net version, don't they? I can guess that in some *nix environments Does this approach work for your current scenario? |
Unfortunately not, I'm try to use serilog to provide a logging service that is used by multiple applications and would like a single unified configuration. In log4net the 'appname' property would be attached to the context of each logger meaning I can have a singular config across loggers that write to multiple files. If I understand correctly what you mean by an environmental variable, it seems with the current suggestion each logger would overwrite the previous value. |
I'm not sure we're on the same page; by definition, wouldn't |
I don't believe so, in the case I'm describing each application has it's own log4net context - so each app could have a property called "appname" with different value (i.e. app1, app2, app3 - which would mean logging to three separate log files) They could all share the same configuration file that would have %property{Appname} in. If we set an environment variable as suggested for serilog it's system wide - so all loggers would pick up this one value, regardless of if they are different applications. Hopefully I'm making sense (and I'm not incorrect). |
Ah, I think this is where we're misunderstanding each other. |
I currently am writing to a statically named log file as defined in my serilog config:
<add key="serilog:write-to:File.path" value="%LOCALAPPDATA%\App_Data\Logs\StaticallyNamedLog.log" />
I'd like to be able to change the logfile name at runtime i.e.
<add key="serilog:write-to:File.path" value="%LOCALAPPDATA%\App_Data\Logs\{appname}-Log.log" />
In log4net for example I'd set a log4net global property value for "appname" in code before the settings were read in. This would then get substituted into this path.
Then in the logfile I'd reference it like so
%property{appname}
This would then get substituted into this path.
I've really tried to find a solution to this but to no avail - can someone offer any advice as to how I might achieve this?
The text was updated successfully, but these errors were encountered: