We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I would like to attach the current log to an email I'm plannig to send during runtime. I'm having a hard time figuring out how to do that though.
Here's my log initialization:
string logFilePath = "Test-{Date}.log"; Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .WriteTo.Console() .WriteTo.RollingFile(logFilePath) .CreateLogger();
I saw related issues, but I couldn't figure out what exactly I need to do with my configuration to get the file path
The text was updated successfully, but these errors were encountered:
I'm going to hell for this, please help me
public static class LoggerExtensions { public static string GetCurrentLogFilePath(this ILogger logger) { FieldInfo? sinkField = Log.Logger.GetType().GetField("_sink", BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic); object sinkObject = sinkField?.GetValue(Log.Logger); FieldInfo? sinksField = sinkObject?.GetType().GetField("_sinks", BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic); ILogEventSink[] sinks = (ILogEventSink[])sinksField?.GetValue(sinkObject); RollingFileSink rollingSink = (RollingFileSink)sinks?.Where(s => s.GetType() == typeof(RollingFileSink)).FirstOrDefault(); FieldInfo? rollerField = rollingSink.GetType().GetField("_currentFile", BindingFlags.Instance | BindingFlags.NonPublic); FileSink fileSink = rollerField.GetValue(rollingSink) as FileSink; FieldInfo? streamField = fileSink?.GetType().GetField("_underlyingStream", BindingFlags.Instance | BindingFlags.NonPublic); FileStream stream = streamField?.GetValue(fileSink) as FileStream; string fileName = stream?.Name; return fileName; } }
Sorry, something went wrong.
You might want to read about FileLifecycleHooks. There's an example here: #191
FileLifecycleHooks
For general usage questions, please use the serilog Stack Overflow tag and we'll do our best to get eyes on it!
serilog
No branches or pull requests
I would like to attach the current log to an email I'm plannig to send during runtime. I'm having a hard time figuring out how to do that though.
Here's my log initialization:
I saw related issues, but I couldn't figure out what exactly I need to do with my configuration to get the file path
The text was updated successfully, but these errors were encountered: