public void LogReport(string Message, System.Diagnostics.EventLogEntryType ELET) { if (pLogParams != null) { if (pLogParams.UseEventLog) { //this.EventLog.WriteEntry(Message, ELET); this.eventLog1.WriteEntry(Message, ELET); System.Diagnostics.Trace.WriteLine(ELET.ToString() + " :" + Message); } if (pLogParams.UseFileLog && pLogParams.LogFile.ToString() != "") { try { string FileName = "";//string FileName = pLogParams.LogFile; if (FileName == string.Empty || FileName == "") { FileName = System.IO.Path.GetDirectoryName(GetType().Assembly.Location) + "STKServiceLogFile.txt"; } System.IO.TextWriter LogFile = new System.IO.StreamWriter(FileName, true); if (ELET == System.Diagnostics.EventLogEntryType.Error) { LogFile.WriteLine(System.DateTime.Now.ToString() + " Error: " + Message); } else if (ELET == System.Diagnostics.EventLogEntryType.Warning) { LogFile.WriteLine(System.DateTime.Now.ToString() + " Warning: " + Message); } else { LogFile.WriteLine(System.DateTime.Now.ToString() + Message); } LogFile.Close(); LogFile = null; } catch { } } } else { this.eventLog1.WriteEntry(System.DateTime.Now.ToString() + Message, ELET); if (ELET == System.Diagnostics.EventLogEntryType.Error) { System.Diagnostics.Trace.WriteLine(System.DateTime.Now.ToString() + " Error: " + Message); } else if (ELET == System.Diagnostics.EventLogEntryType.Warning) { System.Diagnostics.Trace.WriteLine(System.DateTime.Now.ToString() + " Warning: " + Message); } else { System.Diagnostics.Trace.WriteLine(System.DateTime.Now.ToString() + Message); } } return; }
public void LogReport(string Message, System.Diagnostics.EventLogEntryType ELET) { System.Diagnostics.Trace.WriteLine(ELET.ToString() + " :" + Message); //this.eventLog1.WriteEntry(System.DateTime.Now.ToString() + Message, ELET); if (ELET == System.Diagnostics.EventLogEntryType.Error) { System.Diagnostics.Trace.WriteLine(System.DateTime.Now.ToString() + " Error: " + Message); } else if (ELET == System.Diagnostics.EventLogEntryType.Warning) { System.Diagnostics.Trace.WriteLine(System.DateTime.Now.ToString() + " Warning: " + Message); } else { System.Diagnostics.Trace.WriteLine(System.DateTime.Now.ToString() + Message); } return; }
public static void Write(string ApplicationName, string LogText, System.Diagnostics.EventLogEntryType EventLogType, int EventID) { //StringBuilder logPath = new StringBuilder(Environment.CurrentDirectory + "\\Logs"); StringBuilder logPath = new StringBuilder(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\Logs"); if (!Directory.Exists(logPath.ToString())) { Directory.CreateDirectory(logPath.ToString()); } string fileName = "Log-" + DateTime.Today.ToString("yyyy-MM-dd") + ".txt"; logPath.Append("\\" + fileName); if (!File.Exists(logPath.ToString())) { FileStream f = File.Create(logPath.ToString()); f.Close(); } StreamWriter sw = new StreamWriter(logPath.ToString(), true); sw.WriteLine(DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss tt") + ": " + LogText + ", EventID: " + EventID + ", EventLogType: " + EventLogType.ToString()); sw.Flush(); sw.Close(); EventLog.WriteEntry(ApplicationName, LogText, EventLogType, EventID); }