Skip to content
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

Header repeated every 30 mins when Serilog configured to rollOnFileSizeLimit #3

Open
pmerwood opened this issue Jun 21, 2020 · 2 comments
Assignees
Labels
waiting on upstream AN upstream issue needs to be resolved

Comments

@pmerwood
Copy link

pmerwood commented Jun 21, 2020

A Header is being incorrectly added to a log file at exactly 30 min intervals when Serilog is configured to roll a log file when reaching a file size limit. Our Serilog initialisation code is shown below:

// Assemble the file header that's written when the log is created and repeated at the top of each log file. header.AppendLine(new string('*', 120)); header.AppendLine(string.Format("Application started at {0} {1}", startTime.ToShortDateString(), startTime.ToShortTimeString())); header.AppendLine(String.Format("Executable: {0}. Version {1}.{2} Build {3}.", System.Reflection.Assembly.GetExecutingAssembly().Location, System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileMajorPart, System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileMinorPart, System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileBuildPart)); header.AppendFormat("Environment: Host = '{0}'; Operating System = '{1}', Region = '{2}'; Installed UI Culture = '{3}'.", Environment.MachineName, Environment.OSVersion, culture.EnglishName, culture.Name);
Log.Logger = new LoggerConfiguration()
	.Enrich.FromLogContext()
	.Enrich.WithThreadId()
	.Enrich.WithThreadName()

	.MinimumLevel.ControlledBy(levelSwitch)

	.WriteTo.File(FileName,
		buffered: false,
		fileSizeLimitBytes: Size * 1048576,  // Convert to Bytes
		retainedFileCountLimit: Retain,
		rollOnFileSizeLimit: true,
		outputTemplate: "{Timestamp:dd/MM/yyyy HH:mm:ss.fff} {Level:u3} [{ThreadId} {ThreadName}] {Message:lj}{NewLine}{Exception}",
		hooks: new HeaderWriter(header.ToString,true))

 .CreateLogger();
@cocowalla cocowalla self-assigned this Jun 21, 2020
@cocowalla
Copy link
Owner

I've been able to replicate this. As I thought, it's an issue in the Serilog File Sink, rather than this extension - I'll go ahead and open an issue in that repo, linking it back to here.

@pmerwood
Copy link
Author

Thanks for following up. I’ve had a look at the issue you’ve logged for the serilog-file-sink and will watch that with interest.

@cocowalla cocowalla added the waiting on upstream AN upstream issue needs to be resolved label Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting on upstream AN upstream issue needs to be resolved
Projects
None yet
Development

No branches or pull requests

2 participants