Is there a way to get the full filename from the Log Class?
The logger creates a file with a format like C:\MyPath\log-20160631.txt
I can not access the source filename which i used for the init of the logger.
Edit: Here is the init of the logger:
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.LiterateConsole()
.WriteTo.RollingFile(@"C:\MyPath\log.txt")
.CreateLogger();
In every location in the code i can use e.g. Log.Information()
but how i get the Sink information? I want to get the filename which i passed to rolling file sink.
My current workaround is to generate the real file manually (crazy ugly code):
public string LogFilename
{
get
{
string path = Path.GetDirectoryName(LogFilenameTemplate);
string filenameWithoutExtension = Path.GetFileNameWithoutExtension(LogFilenameTemplate);
string extension = Path.GetExtension(LogFilenameTemplate);
string date = DateTime.Now.ToString("yyyyMMdd");
string fullFilename = Path.Combine(path, filenameWithoutExtension + "-" + date + extension);
return fullFilename;
}
}
Format i got from GitHub Repo.