-
Notifications
You must be signed in to change notification settings - Fork 296
Self-Diagnostics: include datetimestamp in filename #2325
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ namespace Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.Sel | |
| { | ||
| using System; | ||
| using System.Diagnostics; | ||
| using System.Globalization; | ||
| using System.IO; | ||
| using System.IO.MemoryMappedFiles; | ||
| using System.Text; | ||
|
|
@@ -38,6 +39,8 @@ internal class MemoryMappedFileHandler : IDisposable | |
|
|
||
| public int LogFileSize { get => this.logFileSize; private set => this.logFileSize = value; } | ||
|
|
||
| public string CurrentFilePath => this.underlyingFileStreamForMemoryMappedFile?.Name; | ||
|
|
||
| /// <summary> | ||
| /// Create a log file. If the file already exists, it will be overwritten. | ||
| /// </summary> | ||
|
|
@@ -48,8 +51,7 @@ public void CreateLogFile(string logDirectory, int fileSize) | |
| try | ||
| { | ||
| Directory.CreateDirectory(logDirectory); | ||
| var fileName = Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName) + "." | ||
| + Process.GetCurrentProcess().Id + ".log"; | ||
| var fileName = GenerateFileName(); | ||
| var filePath = Path.Combine(logDirectory, fileName); | ||
|
|
||
| // Because the API [MemoryMappedFile.CreateFromFile][1](the string version) behaves differently on | ||
|
|
@@ -162,6 +164,17 @@ public virtual void Write(byte[] buffer, int byteCount) | |
| } | ||
| } | ||
|
|
||
| private static string GenerateFileName() | ||
| { | ||
| var dateTimeStamp = DateTime.UtcNow.ToString("yyyyMMdd-HHmmss", CultureInfo.InvariantCulture); | ||
|
|
||
| var currentProcess = Process.GetCurrentProcess(); | ||
| var processFileName = Path.GetFileName(currentProcess.MainModule.FileName); | ||
| var processId = currentProcess.Id; | ||
|
|
||
| return $"{dateTimeStamp}.{processFileName}.{processId}.log"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding 2: Testing this locally... I don't see multiple files being created unless the config file is changed during runtime.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding 3: please see my changes to the Readme and let me know if that makes sense :)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I meant it might give customers an impression that we do partition into multiple files. In fact, as we understand, our code only writes in single file. |
||
| } | ||
|
|
||
| /// <summary> | ||
| /// Try to get the log stream which is seeked to the position where the next line of log should be written. | ||
| /// </summary> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.