public override void Error(Exception exception, string fmt, params object[] vars) { base.Error(exception, fmt, vars); var msg = String.Format(fmt, vars); var fullMsg = "Exception Details=" + ExceptionUtils.FormatException(exception, includeContext: true); var log = new LogRecord { LogLevel = LogLevel.Error, ShortMessage = msg, FullMessage = fullMsg, //CreatedOnUtc = DateTime.UtcNow CreatedOnUtc = DateTime.Now }; logRepository.CreateAsync(log); }
static void BackupLogFile(FileReference LogFile, TimeSpan RetentionSpan) { string LogPrefix = LogFile.GetFileNameWithoutExtension() + "-backup-"; string LogSuffix = LogFile.GetExtension(); if (FileReference.Exists(LogFile)) { string Timestamp = FileReference.GetLastWriteTime(LogFile).ToString("yyyy.MM.dd-HH.mm.ss"); string UniqueSuffix = ""; for (int NextSuffixIdx = 2; ; NextSuffixIdx++) { FileReference BackupLogFile = FileReference.Combine(LogFile.Directory, String.Format("{0}{1}{2}{3}", LogPrefix, Timestamp, UniqueSuffix, LogSuffix)); if (!FileReference.Exists(BackupLogFile)) { try { FileReference.Move(LogFile, BackupLogFile); } catch (Exception Ex) { Log.TraceWarning("Unable to backup {0} to {1} ({2})", LogFile, BackupLogFile, Ex.Message); Log.TraceLog(ExceptionUtils.FormatException(Ex)); } break; } UniqueSuffix = String.Format("_{0}", NextSuffixIdx); } } DateTime DeleteTime = DateTime.UtcNow - RetentionSpan; foreach (FileInfo File in new DirectoryInfo(LogFile.Directory.FullName).EnumerateFiles(LogPrefix + "*" + LogSuffix)) { if (File.LastWriteTimeUtc < DeleteTime) { File.Delete(); } } }
public void Error(Exception exception, string fmt, params object[] vars) { var msg = String.Format(fmt, vars); Trace.TraceError(string.Format(fmt, vars) + ";Exception Details={0}", ExceptionUtils.FormatException(exception, includeContext: true)); }
public void Error(Exception exception, string fmt, params object[] vars) { string msg = String.Format(fmt, vars); Console.WriteLine("[ERROR]" + msg + "; \r\nException Details= ", ExceptionUtils.FormatException(exception, includeContext: true)); }
public static string ReportAllProperties <T>(this T instance) where T : class { try { if (instance == null) { return(string.Empty); } var strListType = typeof(List <string>); var strArrType = typeof(string[]); var arrayTypes = new[] { strListType, strArrType }; var handledTypes = new[] { typeof(Int32), typeof(String), typeof(bool), typeof(DateTime), typeof(double), typeof(decimal), strListType, strArrType }; var validProperties = instance.GetType() .GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) .Where(prop => handledTypes.Contains(prop.PropertyType)) .Where(prop => prop.GetValue(instance, null) != null) .ToList(); var format = string.Format("{{0,-{0}}} : {{1}}", validProperties.Count > 0 ? validProperties.Max(prp => prp.Name.Length) : 10); return(string.Join( Environment.NewLine, validProperties.Select(prop => string.Format(format, prop.Name, (arrayTypes.Contains(prop.PropertyType) ? string.Join(", ", (IEnumerable <string>)prop.GetValue(instance, null)) : prop.GetValue(instance, null)))))); } catch (Exception exception) { return(string.Format("ReportAllProperties fails because of exception = ({0})", ExceptionUtils.FormatException(exception))); } }