Use the params keyword
//The new Logger for the exe
static void WriteLog(string exception, int status, params string[] arguments)
{
string logFile = string.Format("D:\\TempLogs\\Grep-{0:yyyy-MM-dd_hh-mm-ss-tt}.log", DateTime.Now);
StreamWriter grepLog = new StreamWriter(logFile, true);
grepLog.WriteLine("Status: " + status.ToString() + " (0 for PASS, 1 for FAIL)");
grepLog.WriteLine("Exception: " + exception);
// TODO: Consider logging "no arguments" if that is the case.
for(int i=0; i<arguments.Length; i++)
{
grepLog.WriteLine("Argument " + i + ": " + arguments[i]);
}
grepLog.Close();
}
Use an enum for status
Since the status has 3 states, use an enum for it. This will help you avoid mistakes.
Why do you try-catch while logging?
If you don't see any particular possibility for the log to fail, then simply assume it and don't try-catch the logging.
If you want the logging to no matter what not break the application with exceptions, and you cannot fix those exceptions (why?), then I would suggest putting the try-catch inside the logging method.
Main - exception should catch, log, and return
I would have the exception log the error and return, instead of continuing normally.
Alternatively, I would catch, log, and re-throw: try { ... } catch (Exception e) { WriteLog(...); throw; }
Use camelCase for local variables
StreamWriter grepLog;
Using a starting underscore (_grepLog) is also common for private fields.
Follow the de-facto conventions. (See e.g. http://stackoverflow.com/questions/2976627/on-c-sharp-naming-conventions-for-member-variableshttps://stackoverflow.com/questions/2976627/on-c-sharp-naming-conventions-for-member-variables )
Avoid Hungarian Notation
In string strGrepLogFileName, the part "str" brings nothing new.
If you change the variable's type (e.g. to an Uri) without changing its meaning, you should not have to rename the variable, and using Hungarian Notation you do.