Claro PepeS. Trabajar con un archivo es una buena idea, aunque también lo puedes hacer con los eventos de Windows. De esta manera, quien se siente en la computadora será la persona de la que se guarde información. Te dejo un código:
class Program
{
public const string Source = "MyConsoleApplication";
public const string LogName = "MyCustomLog";
static void Main(string[] args)
{
int NumberOfTurns = 0;
if (!EventLog.SourceExists(Source))
EventLog.CreateEventSource(Source, LogName);
do
{
//When you have an error in your application
if (NumberOfTurns == 0)
EventLog.WriteEntry(Source, GetMesssage("Error"), EventLogEntryType.Error, 111, 20);
else if(NumberOfTurns ==1)
EventLog.WriteEntry(Source, GetMesssage("FailureAudit"), EventLogEntryType.FailureAudit, 222,21);
//When your application executed something without problems
else if (NumberOfTurns == 2)
EventLog.WriteEntry(Source, GetMesssage("Information"), EventLogEntryType.Information, 333,22);
else if (NumberOfTurns == 3)
EventLog.WriteEntry(Source, GetMesssage("SuccessAudit"), EventLogEntryType.SuccessAudit, 444,23);
//When your application found something suspect at the moment to ran
else if (NumberOfTurns == 4)
EventLog.WriteEntry(Source, GetMesssage("Warning"), EventLogEntryType.Warning, 555,24);
NumberOfTurns++;
} while (NumberOfTurns<5);
}
public static string GetMesssage(string MessageType)
{
if (MessageType == "Error")
return "The application fail";
else if (MessageType == "FailureAudit")
return "There is something wrong";
else if (MessageType == "Information")
return "The operation was executed successfully";
else if (MessageType == "SuccessAudit")
return "The application run ok";
else
return "Warning: Behavior suspect";
}
}
Ya los resultados los ves desde: Herramientas Administrativas > Visor de Eventos > Registros de Windows