private void Log(object caller, string logmessage, LogLevel loggingLevel) { if (loggingLevel > _logLevel) { return; } if (caller == null) { caller = new object(); } if (OnLogInformation == null) { return; } Task.Run(() => { try { OnLogInformation.Invoke(DateTime.Now, caller.GetType()?.Name, logmessage, loggingLevel); } catch (Exception) { // ignored } }); }
/// <summary> /// Log an information event to the event log. If we can't write to the event log, nothing happens. /// </summary> /// <param name="text">The event text.</param> /// <param name="pid">The event program source.</param> public static void LogInformation(string text, string pid) { if (PhazeXLog.writeFileLog) { try { if (Filename != null) { StreamWriter sw = new StreamWriter(Filename, true, Encoding.ASCII); DateTime dt = DateTime.Now; sw.Write("[Information] [" + dt.ToShortDateString() + " " + dt.ToLongTimeString() + "] "); sw.Write(text + newLine); sw.Close(); } } catch { } } #if !PocketPC if (WriteEventLog) { try { EventLog.WriteEntry(pid, text, EventLogEntryType.Information); } catch { } } #endif if (OnLogInformation != null) { OnLogInformation.Invoke(text, pid); } }