If you want to use it in all classes, then make it static
.
You could have a static
LogHelper
class to better organise it, like:
public static class LogHelper
{
public static void Log(String line)
{
var file = System.IO.Path.GetPathRoot(Environment.SystemDirectory)+ "Logs.txt";
StreamWriter logfile = new StreamWriter(file, true);
// Write to the file:
logfile.WriteLine(DateTime.Now);
logfile.WriteLine(line);
logfile.WriteLine();
// Close the stream:
logfile.Close();
}
}
Then call it by doing LogHelper.Log(line)