-
Notifications
You must be signed in to change notification settings - Fork 125
How do I determine logfile path which is being written to? #154
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
Comments
Information about sinks isn't exposed at runtime, so I think your best bet would be to capture the directory name at startup when you're configuring the logger. For example, if you're configuring from |
See also: #129 - the hook approach might also be an option to consider. |
@nblumhardt while you could use the |
Ah, thanks! Forgot about that hitch. I'd be more inclined to pass the filename as an additional argument to the hook method, in case we want to use different stream types in the future - I remember that this was of limited use to hooks that need to reopen the file, but it could be a reasonable step forwards (and is fairly straightforward to implement in a backwards-compatible way). What do you think? |
Thanks for the quick consideration. I like the idea of exposing it there.
Of course, my program does save it where I CreateLogger, but I've been
around enough to know that when I maintain legacy code it's sure nice to
find out what's *currently* being used by a class. Let me know if you
implement something through this thread!
…On Wed, Jun 17, 2020 at 5:43 PM Nicholas Blumhardt ***@***.***> wrote:
Ah, thanks! Forgot about that hitch.
I'd be more inclined to pass the filename as an additional argument to the
hook method, in case we want to use different stream types in the future -
I remember that this was of limited use to hooks that need to reopen the
file, but it could be a reasonable step forwards (and is fairly
straightforward to implement in a backwards-compatible way). What do you
think?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#154 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIXCXETC6LNJ2EVFPP3J3TRXFBKHANCNFSM4OA4WKVA>
.
|
@nblumhardt yes, with hooks being the extensibility point, I think it makes sense to provide the filename there. Only question was whether it should be through a Do you mean to change the signature of the existing public virtual Stream OnFileOpened(Stream underlyingStream, Encoding encoding) => underlyingStream; would become: public virtual Stream OnFileOpened(Stream underlyingStream, Encoding encoding, string path) => underlyingStream; Technically a breaking change, as hooks would need to be updated, but because the hooks mechanism is still quite new, I'm not sure if it's a big deal. Happy to make the change once we're aligned on what exactly it should be 😄 |
Roughly, yes 👍 - I'd probably put the The change doesn't need to be breaking - we can add the new signature, give it a default implementation that calls the old signature without passing |
Also need a way to open the current log file at runtime. |
I tried the hook approach in order to get the current log file location on disk, but as soon as I add the hook in my public class SerilogHooks
{
public static SerilogFileCycleHook FileCycleHook => new SerilogFileCycleHook();
}
public class SerilogFileCycleHook : FileLifecycleHooks
{
public string CurrentLoggingFilePath { get; private set; }
public override Stream OnFileOpened(string path, Stream underlyingStream, Encoding encoding)
{
CurrentLoggingFilePath = path;
return base.OnFileOpened(path, underlyingStream, encoding);
}
} While debugging I can see the hook is initiated and I can get the log file path ... but as the file stays empty now, this is not very useful ;) Any chance we could get a bit more easily the current log file location ? I am using Serilog 2.1 with Serilog.Sinks.file 5.0.0 Thanks |
@Grendizr We have a number of tests covering hooks usage and overall it's very unlikely that we would have a bug so basic as the one you are describing - as that would make hooks completely unusable. You must have one or more bugs in your own code, causing the file to be empty. For a start, it looks like you have a bug here: public class SerilogHooks
{
public static SerilogFileCycleHook FileCycleHook => new SerilogFileCycleHook();
} You're creating a brand new instance of You probably meant to write: public class SerilogHooks
{
public static SerilogFileCycleHook FileCycleHook { get; } = new SerilogFileCycleHook();
} Anyway, for Serilog usage troubleshooting please post questions on StackOverflow under the If you really think you found a bug, provide a minimal reproducible code sample. |
Hi! We're triaging issues in this tracker and the current one appears to be stale. If your issue relates to a usage question, asking on Stack Overflow and posting a link here will get the most eyes on it (only a small number of maintainers actively track this repository). If your issue relates to a possible bug that still needs attention, please feel free to comment/request reopening. Thanks! |
As a user, sometimes I have trouble finding where the programmer directed the log (it was so obvious to him/her). As a programmer, I would like to give a message to the user on error where to find a log with more information. I may be missing it, but I don't see how to expose the path name of the current log file as information is being logged. Thanks!
The text was updated successfully, but these errors were encountered: