Loading...
 
JoiWiki » Developer » .Net » .Net Snippets » Quick and Dirty Log File Quick and Dirty Log File

Quick and Dirty Log File

 

It's often the case that you want an output of information from an exe on the operation of the thing, especially if your exe is allowed to run without a form being presented to the user. There are a great many methods to do this and there will be patterns designed to allow for logging to a file that allow you to avoid cross cutting concerns (Here's a worthy article). This isn't that, this isn't good practice in any way shape or form but if you just want to escape some information from your assembly here's a dirty little solution taht provides the end point method, actually writing to a log file - maybe this would suit a singleton? here we go though:

 

/// <summary>
/// Hard coded file location (app.startuppath), takes a string and throws it at the log file (creates if not present)
/// </summary>
/// <param name="_Message"></param>
public static void AppendToLog(string _Message)
{
	string path = String.Format(@"{0}\ArgsLog.txt", Application.StartupPath);
	using (var tw = new StreamWriter(path, true))
	{
		tw.WriteLine(_Message);
	}
}











 

 



Created by JBaker. Last Modification: Thursday September 26, 2019 15:26:16 BST by JBaker.

Developer