Skip to content

Instantly share code, notes, and snippets.

@xoofx
Created January 15, 2013 14:23
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xoofx/4539007 to your computer and use it in GitHub Desktop.
Save xoofx/4539007 to your computer and use it in GitHub Desktop.
Tracking read and write files by current process using FileTracker available from Microsoft.Build.Utilities.v4.0 assembly
using System.IO;
using Microsoft.Build.Utilities;
namespace TestFileTracker
{
class Program
{
static void Main(string[] args)
{
// Add Reference the assembly Microsoft.Build.Utilities.v4.0 to your project
// Output dir and prefix for logs
var outputDir = "mytest";
var outputFilePrefix = "mytask";
// Start tracking all file access from this process
FileTracker.StartTrackingContext(outputDir, outputFilePrefix);
// Read and Write files
File.WriteAllText("file.txt", "YES!!!!!!");
var test = File.ReadAllText(@"..\..\FileTrackerTest.cs");
// Write the logs to "mytest\mytask.read.1.tlog" and "mytest\mytask.write.1.tlog"
FileTracker.WriteContextTLogs(outputDir, outputFilePrefix);
// End tracking
FileTracker.EndTrackingContext();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment