/// <summary> /// Escreve log em um arquivo. /// </summary> /// <param name="message">Mensagem para logar.</param> public void WriteLog(LogSeverityEnum severity, string message, object args = null) { string serializedObject = null; if (args != null) { serializedObject = Serializer.JsonSerialize(args); } string sSource = Assembly.GetCallingAssembly().FullName; string sLog = string.Format(CultureInfo.InvariantCulture, "{0} {1}", message, serializedObject); string sEvent = severity.ToString(); if (!EventLog.SourceExists(sSource)) { EventLog.CreateEventSource(sSource, "Application"); } EventLog.WriteEntry(sSource, sLog); }
/// <summary> /// Escreve log em um arquivo. /// </summary> /// <param name="message">Mensagem para logar.</param> public void WriteLog(LogSeverityEnum severity, string message, object args = null) { string path = this.ConfigurationUtility.LogFilePath; string fileName = this.ConfigurationUtility.LogFileName; try { if (Directory.Exists(path) == false) { Directory.CreateDirectory(path); } FileStream fileStream = new FileStream(Path.Combine(path, fileName), FileMode.Append); using (StreamWriter streamWriter = new StreamWriter(fileStream)) { string serializedObject = null; if (args != null) { serializedObject = Serializer.JsonSerialize(args); } streamWriter.WriteLine(string.Format("[{0}] [{1}] {2} {3}", DateTime.Now.ToString(), severity.ToString().PadRight(15), message, serializedObject)); } } catch (Exception) { } }
protected override void LogIt(LogSeverityEnum severity, string msg) { Console.WriteLine($"{System.DateTime.Now.ToString("HH:mm:ss")} | {severity.ToString()} | {msg}"); }