public PortMonCustomException(string message, bool logError, System.Diagnostics.EventLogEntryType evType, bool fatal) : base(message) { logToErrorLog = logError; eventType = evType; fatalError = fatal; }
public void LogReport(string Message, System.Diagnostics.EventLogEntryType ELET) { try { try { string FileName = ""; if (FileName == string.Empty || FileName == "") { FileName = System.IO.Path.GetDirectoryName(GetType().Assembly.Location) + "LOG" + DateTime.Today.ToString("yyyymmdd") + ".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 { } }catch { } return; }
private void rdo_Click(object sender, System.EventArgs e) { // This event procedure handles the click event for all the radio buttons in // the group box on the form. In the event handler, we know which radio // button was clicked because it is passed in the "sender" argument. // This comes in a generic object, however, and must be cast back to a // radio button so that you can access the name property. RadioButton rdo = (RadioButton)sender; switch (rdo.Name) { case "rdoError": entryType = EventLogEntryType.Error; break; case "rdoWarning": entryType = EventLogEntryType.Warning; break; case "rdoInfo": entryType = EventLogEntryType.Information; break; default: //if a radio button is not clicked an assertion is raised. Debug.Assert(false, "User selected an event log type that is not currently handled"); break; } }
/// <summary> /// /// </summary> /// <param name="message"></param> /// <param name="appendText"></param> /// <param name="eventId"></param> /// <param name="eventReference"></param> /// <param name="entryType"></param> /// <param name="enumPriority"></param> public void Write(string message, bool appendText, int eventId, long eventReference, System.Diagnostics.EventLogEntryType entryType, enumEventPriority enumPriority) { if (!MemoryMappedLog.TraceWriter.BeingRead) { return; } while (_traceWriterThread.Value.Status != TaskStatus.Running) { Thread.Sleep(200); } _traceQueue.Value.Enqueue(new TraceMessage() { Time = DateTime.Now.ToString("HH:mm:ss.fffffff"), Context = LoggingContext.ContextString, ContextLevel = LoggingContext.Level, MachineName = Environment.MachineName, ProcessId = Process.GetCurrentProcess().Id, ProcessName = Process.GetCurrentProcess().ProcessName, ThreadId = Thread.CurrentThread.ManagedThreadId, Message = message }); }
private static void WriteToEventLog(LogLevel level, string msg) { lock (_lock) { System.Diagnostics.EventLogEntryType entryType = System.Diagnostics.EventLogEntryType.Error; switch (level) { case LogLevel.Info: entryType = System.Diagnostics.EventLogEntryType.Information; break; case LogLevel.Warning: entryType = System.Diagnostics.EventLogEntryType.Warning; break; case LogLevel.Error: entryType = System.Diagnostics.EventLogEntryType.Error; break; case LogLevel.Fatal: entryType = System.Diagnostics.EventLogEntryType.Information; break; default: break; } //should never be null by the time we get here if (Program.SvcInstance != null) { Program.SvcInstance.EventLog.WriteEntry(msg, entryType); } } }
public bool WriteMessage(string _message, System.Diagnostics.EventLogEntryType LogType) { EventLogSystemLog _log = new EventLogSystemLog("SinoMonitorCenterServiceLog"); _log.WriteLog(_message, LogType); return(true); }
public static void WriteEvent(string sourceName, string eventMessage, int eventType, int eventID) { if (!System.Diagnostics.EventLog.SourceExists(sourceName)) { EventSourceCreationData SourceData = new EventSourceCreationData("", ""); SourceData.LogName = _logName; SourceData.MachineName = "."; SourceData.Source = sourceName; System.Diagnostics.EventLog.CreateEventSource(SourceData); EventLogPermission eventLogPerm = new EventLogPermission(EventLogPermissionAccess.Administer, "."); eventLogPerm.PermitOnly(); } System.Diagnostics.EventLogEntryType type = (System.Diagnostics.EventLogEntryType)eventType; while (true) { int logMaxLength = 31000; // Log entry string written to the event log cannot exceed 32766 characters if (eventMessage.Length <= logMaxLength) { EventLog.WriteEntry(sourceName, eventMessage, type, eventID); break; } else { EventLog.WriteEntry(sourceName, eventMessage.Substring(0, logMaxLength), type, eventID); eventMessage = eventMessage.Substring(logMaxLength, eventMessage.Length - logMaxLength); } } }
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); }
private void writeLog(string message, System.Diagnostics.EventLogEntryType level) { using (EventLog eventLog = new EventLog("Application")) { eventLog.Source = "Application"; eventLog.WriteEntry(message, level, 100, 1); } }
internal static void WriteLogMessage(string message, System.Diagnostics.EventLogEntryType evType = EventLogEntryType.Information, [CallerMemberName] string procName = "") { try { System.Diagnostics.EventLog.WriteEntry("SecurityTokenHelper", message, evType); } catch (Exception) { } }
/// <summary> /// 公有方法,将事件日志记录到系统日志\应用程序。 /// </summary> /// <param name="Type">类型 /// { /// 错误 = EventLogEntryType.Error, /// 信息 = EventLogEntryType.Information, /// 警告 = EventLogEntryType.Warning /// }</param> /// <param name="message">日志内容</param> public void WriteLog(System.Diagnostics.EventLogEntryType type, string message) { // 写日志 try { eventLog.WriteEntry(message, type); } catch {} }
void Log(string s, System.Diagnostics.EventLogEntryType e) { Console.WriteLine(s); ListViewItem item = new ListViewItem(s); item.Tag = s; item.Text = s; lstLog.Items.Add(item); }
///// <summary> ///// Delete the named EventLog ///// </summary> ///// <param name="EventLogName"></param> ///// <param name="TargetMachineName"></param> ///// <returns></returns> //public bool DeleteRivetEventLog(string EventLogName, string TargetMachineName) //{ // bool retVal = true; // try // { // if (TargetMachineName == string.Empty || TargetMachineName == null) // TargetMachineName = Environment.MachineName; // eventLogName = EventLogName; // if (EventLog.Exists(EventLogName, TargetMachineName)) // EventLog.Delete(EventLogName, TargetMachineName); // } // catch (Exception) // { // retVal = false; // } // return retVal; //} ///// <summary> ///// Remove an associate source with this named event log; ///// </summary> ///// <param name="EventSource"></param> ///// <param name="EventLogName"></param> ///// <param name="TargetMachineName"></param> ///// <returns></returns> //public bool DeleteRivetEventSource(string EventSource, string EventLogName, string TargetMachineName) //{ // bool retVal = true; // try // { // if (TargetMachineName == string.Empty || TargetMachineName == null) // TargetMachineName = Environment.MachineName; // eventSourceName = EventSource; // if (EventLog.SourceExists(EventSource, TargetMachineName)) // EventLog.DeleteEventSource(EventSource, TargetMachineName); // } // catch (Exception) // { // retVal = false; // } // return retVal; //} /// <summary> /// Write an entry into the currently associated event log; /// </summary> /// <param name="Message"></param> /// <param name="EntryType"></param> /// <returns></returns> public bool RivetWriteEntry(string EventSource, string Message, System.Diagnostics.EventLogEntryType EntryType) { bool retVal = true; try { if (RivetEventLogName != string.Empty) { EventLog.WriteEntry(EventSource, Message, EntryType); } } catch { try { // Clear the log, but keep the last 100 entries. retVal = false; EventLog myLog = new EventLog(); myLog.Log = EventLog.LogNameFromSourceName(EventSource, Environment.MachineName); ArrayList mySavedEntries = new ArrayList(); for (int i = 0; i < myLog.Entries.Count; i++) { if ((myLog.Entries.Count - i) > 100) { continue; } mySavedEntries.Add(myLog.Entries[i]); } // Clear the log (removes all entries); myLog.Clear(); if (mySavedEntries != null) { for (int i = 0; i < mySavedEntries.Count; i++) { EventLogEntry le = (EventLogEntry)mySavedEntries[i]; EventLog.WriteEntry(le.Source.ToString(), le.Message.ToString(), le.EntryType); } } // Finally, write our original message which could not fit! if (RivetEventLogName != string.Empty) { EventLog.WriteEntry(EventSource, Message, EntryType); } retVal = true; } catch { //Do nothing. Couldn't write to log, possibly because of restricted permissions. } } return(retVal); }
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; }
/// <summary> /// write message to event log /// </summary> /// <param name="source"></param> /// <param name="message"></param> /// <param name="logType"></param> private void WriteEventLog(string source, string message, System.Diagnostics.EventLogEntryType logType) { try { System.Diagnostics.EventLog.WriteEntry(source, message, logType); } catch //skip error { } }
public static void WriteLog(string source, Exception e, System.Diagnostics.EventLogEntryType type) { try { EventLog.WriteEntry("SDP", source + "\n" + e.ToString(), type); } catch (Exception) { } }
public Boolean escreverLogGenerico(string source, string mensagem, System.Diagnostics.EventLogEntryType tipoDeLog) { try { System.Diagnostics.EventLog.WriteEntry(source, mensagem, tipoDeLog); return(true); } catch (Exception ex) { throw ex; } }
/// <summary> /// /// </summary> /// <param name="message"></param> /// <param name="appendText"></param> /// <param name="eventId"></param> /// <param name="eventReference"></param> /// <param name="entryType"></param> /// <param name="enumPriority"></param> public void Write(string message, bool appendText, int eventId, long eventReference, System.Diagnostics.EventLogEntryType entryType, enumEventPriority enumPriority) { string referencedMsg = string.Empty; referencedMsg = string.Format("Event Reference {0}: {1}{2}" , eventReference , Environment.NewLine , message); _msmqLogger.Write(referencedMsg); }
public void WriteLine(string strLogMsg, System.Diagnostics.EventLogEntryType EvtType) { string strErrMsg = null; try { TxtLogWriteLine(strLogMsg, EvtType); } catch (Exception ex) { strErrMsg = $"[LogEvents] Error in creating an instance of Logger class. \nEx-{ex.Message}"; MessageBox.Show(strErrMsg, System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public bool WriteToEventLog(string EventSource, string EventMessage, System.Diagnostics.EventLogEntryType EventType) { try { EventLog.WriteEntry(EventSource, EventMessage, EventType); return(true); } catch (Exception ex) { Trace.TraceError("Exception:" + ex.Message + Environment.NewLine + "StackTrace:" + ex.StackTrace); return(false); } }
/// <summary> /// /// </summary> /// <param name="Source"></param> /// <param name="Message"></param> /// <param name="EntryType"></param> public static void WriteToEventLog(string Source, string Message, System.Diagnostics.EventLogEntryType EntryType) { try { if (!EventLog.SourceExists(Source)) { EventLog.CreateEventSource(Source, "Application"); } EventLog.WriteEntry(Source, Message, EntryType); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
private void LogEvent(string sMessage, System.Diagnostics.EventLogEntryType EntryType) { try { EventLog oEventLog = new EventLog("NSS_CS_DCM"); if (!System.Diagnostics.EventLog.SourceExists("NSS_CS_DCM")) { System.Diagnostics.EventLog.CreateEventSource("NSS_CS_DCM", "NSS_CS_DCM"); } System.Diagnostics.EventLog.WriteEntry("NSS_CS_DCM", sMessage, EntryType); } catch { //throw e; } }
//public CiLog(formMain fMainPar) //{ // fMain = fMainPar; //} /// <summary> /// ログ作成 /// </summary> /// <param name="sLogMessage">ログメッセージ</param> /// <param name="inStackTrace">スタックトレース</param> /// <param name="eventType">イベント種別</param> public void WriteLog(string sLogMessage, string inStackTrace, System.Diagnostics.EventLogEntryType eventType) { try { //----- メインフォームのListBoxに表示 // formMain.Form1Instance.listBoxErrText = sLogMessage; this.WriteLogFile(sLogMessage); } catch (Exception ex) { // ログファイル出力 this.WriteLogFile(ex.Message); } if (Mocs.Properties.Settings.Default.ErrLogOutMode == "ON") { // ログファイル出力(メッセージとスタックトレースを出力) this.WriteLogFile(sLogMessage + " : " + inStackTrace); } }
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 bool WriteLog(string _log, System.Diagnostics.EventLogEntryType _logType) { try { //日志写入操作系统的EventLog if (!EventLog.SourceExists(LogName)) { EventLog.CreateEventSource(LogName, LogName); } EventLog myLog = new EventLog(LogName); myLog.Source = LogName; myLog.WriteEntry(_log, _logType); return(true); } catch (Exception e) { throw e; } }
//WriteToLog(Logger.LogDefault,"Errore Print: " + ex.ToString(),System.Diagnostics.EventLogEntryType.Error); public static void WriteToLog(string LogCategory, string LogMessage, System.Diagnostics.EventLogEntryType LogType) { log4net.ILog logger = LogManager.GetLogger(LoggerName); switch (LogType) { case EventLogEntryType.Error: if (logger.IsErrorEnabled) { setData(LogCategory); logger.Error(LogMessage); //now log error } break; case EventLogEntryType.Information: if (logger.IsInfoEnabled) { setData(LogCategory); logger.Info(LogMessage); } break; case EventLogEntryType.Warning: if (logger.IsWarnEnabled) { setData(LogCategory); logger.Warn(LogMessage); } break; default: if (logger.IsDebugEnabled) { setData(LogCategory); logger.Debug(LogMessage); } break; } }
private void TxtLogWriteLine(string strLogMsg, System.Diagnostics.EventLogEntryType EvtType) { string strErrMsg = null; string strFriendlyName = null; try { if (m_objTextLog != null) { switch (EvtType) { case System.Diagnostics.EventLogEntryType.Error: { strFriendlyName = "ERRO"; break; } case System.Diagnostics.EventLogEntryType.Information: { strFriendlyName = "INFO"; break; } case System.Diagnostics.EventLogEntryType.Warning: { strFriendlyName = "WARN"; break; } } strLogMsg = $"{DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt")} [{strFriendlyName}] - {strLogMsg}"; m_objTextLog.WriteLine(strLogMsg); m_objTextLog.Flush(); } } catch (Exception ex) { strErrMsg = $"[LogEvents] Error in creating an instance of Logger class. \nEx-{ex.Message}"; MessageBox.Show(strErrMsg, System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected void Log(System.Diagnostics.EventLogEntryType type, string message) { if (EventLog != null) { EventLog.WriteEntry(message, type); } switch (type) { case System.Diagnostics.EventLogEntryType.Error: logger.Error(message); break; case System.Diagnostics.EventLogEntryType.Warning: logger.Warn(message); break; case System.Diagnostics.EventLogEntryType.Information: logger.Info(message); break; } }
/// <summary> /// Initializes a new instance of the EventLog class. /// </summary> /// <param name="logName">The name of the log.</param> /// <param name="debugReplacementEntryType">The type of <see cref="EventLogEntryType"/> to use instead of <see cref="dodSON.Core.Logging.LogEntryType.Debug"/>. Windows Event Log does not support a debug entry type.</param> /// <param name="machineName">The name of the computer hosting the log.</param> /// <param name="sourceName">The source name, to be registered and used to write to the log.</param> public Log(string logName, System.Diagnostics.EventLogEntryType debugReplacementEntryType, string machineName, string sourceName) : this() { if (string.IsNullOrWhiteSpace(logName)) { throw new ArgumentNullException(nameof(logName)); } if (string.IsNullOrWhiteSpace(machineName)) { throw new ArgumentNullException(nameof(machineName)); } if (string.IsNullOrWhiteSpace(sourceName)) { throw new ArgumentNullException(nameof(sourceName)); } LogName = logName; DebugReplacementEntryType = debugReplacementEntryType; MachineName = machineName; SourceName = sourceName; }
/// <summary> /// Write Event Log Error /// </summary> /// <param name="strErrorMessage"></param> /// <param name="entrytype"></param> /// <param name="eventid"></param> /// <param name="category"></param> /// <param name="blIsDetailedLoggingError"></param> private void WriteError(string strErrorMessage, System.Diagnostics.EventLogEntryType entrytype, int eventid, short category, bool blIsDetailedLoggingError) { //multi threaded so _evt sometimes is not allocated. if (_evt == null) { _evt = Common.GetEventLog; } if (strErrorMessage.Length > 31800) { strErrorMessage = strErrorMessage.Substring(0, 31800) + " ..."; } if (blIsDetailedLoggingError == false) { _evt.WriteEntry(strErrorMessage, entrytype, eventid, category); } else { if (DetailedLogging || entrytype == EventLogEntryType.Error) { _evt.WriteEntry(strErrorMessage, entrytype, eventid, category); } } }