Skip to content

Commit

Permalink
Remove missing type inside CoreLib from the ModuleTrackerTemplate (#1286
Browse files Browse the repository at this point in the history
)

Remove missing type inside CoreLib from the ModuleTrackerTemplate
  • Loading branch information
MarcoRossignoli committed Jan 31, 2022
1 parent df968b8 commit d427957
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/coverlet.core/Instrumentation/ModuleTrackerTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ internal static class ModuleTrackerTemplate
public static bool SingleHit;
public static bool FlushHitFile;
private static readonly bool _enableLog = int.TryParse(Environment.GetEnvironmentVariable("COVERLET_ENABLETRACKERLOG"), out int result) ? result == 1 : false;
private static string _sessionId = Guid.NewGuid().ToString();

static ModuleTrackerTemplate()
{
Expand Down Expand Up @@ -173,7 +174,7 @@ private static void WriteHits(object sender)
Assembly currentAssembly = Assembly.GetExecutingAssembly();
DirectoryInfo location = new DirectoryInfo(Path.Combine(Path.GetDirectoryName(currentAssembly.Location), "TrackersHitsLog"));
location.Create();
string logFile = Path.Combine(location.FullName, $"{Path.GetFileName(currentAssembly.Location)}_{DateTime.UtcNow.Ticks}_{Process.GetCurrentProcess().Id}.txt");
string logFile = Path.Combine(location.FullName, $"{Path.GetFileName(currentAssembly.Location)}_{DateTime.UtcNow.Ticks}_{_sessionId}.txt");
using (var fs = new FileStream(HitsFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
using (var log = new FileStream(logFile, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None))
using (var logWriter = new StreamWriter(log))
Expand All @@ -197,7 +198,7 @@ private static void WriteLog(string logText)
// We don't set path as global var to keep benign possible errors inside try/catch
// I'm not sure that location will be ok in every scenario
string location = Assembly.GetExecutingAssembly().Location;
File.AppendAllText(Path.Combine(Path.GetDirectoryName(location), Path.GetFileName(location) + "_tracker.txt"), $"[{DateTime.UtcNow} P:{Process.GetCurrentProcess().Id} T:{Thread.CurrentThread.ManagedThreadId}]{logText}{Environment.NewLine}");
File.AppendAllText(Path.Combine(Path.GetDirectoryName(location), Path.GetFileName(location) + "_tracker.txt"), $"[{DateTime.UtcNow} S:{_sessionId} T:{Thread.CurrentThread.ManagedThreadId}]{logText}{Environment.NewLine}");
}
}
}
Expand Down

0 comments on commit d427957

Please sign in to comment.