// ---------- CONSTRUCTORS ---------- /// <summary> /// Constructs an Event given its source, date, severity, category, and details about the event. /// </summary> /// <param name="source">An identifier for the application or service from which the event originated.</param> /// <param name="date">The date and time that the event occurred.</param> /// <param name="severity">The severity of the event.</param> /// <param name="category">A category that describes the nature of the event.</param> /// <param name="details">A detailed description of the event.</param> public Event(string source, DateTime date, SeverityLevels severity, string category, string details) { // Check that a source for the event was provided. if (!String.IsNullOrWhiteSpace(source)) { // A source was provided, set its value. Source = source; } else { // No source was provided. Set its value to unknown. Source = UNKNOWN_SOURCE; } // Set the date. Date = date; // Set the severity. Severity = severity; // Check that a category for the event was provided. if (!string.IsNullOrWhiteSpace(category)) { // A category was provided, set its value. Category = category; } else { // No category was provided. Set its value to unknown. Category = UNKNOWN_CATEGORY; } // Set the details of the event. Details = details; }
public static List <string> GetCurrentLogFileLines(SeverityLevels filter, int lineCount, bool lastRows) { string logFile = GetCurrentLogFileName(); lock (_readWriteLock) { return(GetLogFileLines(filter, logFile, lineCount, lastRows)); } }
internal static void PublishMessage(XElement msg) { if (!DesignerProperties.IsInDesignTool) { if (msg == null) { //Clear(); } else { SeverityLevels severity = SeverityLevels.Undefined; string severityString = null; if (msg.Attribute(Common.MessageType) != null) { severityString = msg.Attribute(Common.MessageType).Value.ToUpper(); } switch (severityString) { case "ERROR": severity = SeverityLevels.Error; break; case "WARNING": severity = SeverityLevels.Warning; break; case "SUCCESS": severity = SeverityLevels.Success; break; default: severity = SeverityLevels.Information; break; } if (msg.Attribute(Common.PopupMessage) != null && Common.boolValue(msg.Attribute(Common.PopupMessage).Value)) { MessageBox.Show(msg.Value, severity.ToString(), MessageBoxButton.OK); } else { MessageBox.Show(msg.Value, severity.ToString(), MessageBoxButton.OK); //var toast = new ToastPrompt //{ // Title = severity.ToString(), // Message = msg.Value, // ImageSource = new BitmapImage(new Uri("/Expanz.ThinRIA.Core.WP7;component/Images/" + severity.ToString() + ".png", UriKind.RelativeOrAbsolute)), //}; //toast.Show(); } } } }
public LogEntry(SeverityLevels severityLevel, string message, string assemblyName) { // Store the message this.message = message; // Store the severity level. this.severityLevel = severityLevel; // Store the assemblyy name. this.assemblyName = assemblyName; // For errors, a stack dump may be useful. if (severityLevel == SeverityLevels.Error) { try { stackDump = string.Empty; StackTrace st = new StackTrace(true); foreach (StackFrame frame in st.GetFrames()) { string fileName = (frame != null && frame.GetFileName() != null && frame.GetFileName().Length > 0) ? frame.GetFileName() : string.Empty; string line = (frame != null && frame.GetFileLineNumber() > 0) ? frame.GetFileLineNumber().ToString() : string.Empty; string methodName = (frame != null && frame.GetMethod() != null) ? frame.GetMethod().ReflectedType + "." + frame.GetMethod().Name : string.Empty; string frameStr = string.Empty; if (methodName.Length > 0) { frameStr += " at " + methodName; } if (fileName.Length > 0) { frameStr += " in " + fileName; if (line.Length > 0) { frameStr += ":line " + line; } } stackDump += (frameStr.Length > 0) ? frameStr : " ???? (symbols not available for this stack frame)"; stackDump += "\n"; } stackDump = stackDump.TrimEnd(new char[] { '\n' }); } catch { stackDump = StackDumpNotAvailable; } } GetAppName(); }
/// <summary> /// Publish message to the message panel. /// </summary> /// <param name="msg"></param> public void PublishMessage(XElement msg) { if (!DesignerProperties.GetIsInDesignMode(this)) { if (msg == null) { Clear(); } else { SeverityLevels severity = SeverityLevels.Undefined; string severityString = null; if (msg.Attribute(Common.MessageType) != null) { severityString = msg.Attribute(Common.MessageType).Value.ToUpper(); } switch (severityString) { case "ERROR": severity = SeverityLevels.Error; break; case "WARNING": severity = SeverityLevels.Warning; break; case "SUCCESS": severity = SeverityLevels.Success; break; default: severity = SeverityLevels.Information; break; } Severity = severity; Message = msg.Value; VisualStateManager.GoToState(this, severity.ToString(), true); if (msg.Attribute(Common.PopupMessage) != null && Common.boolValue(msg.Attribute(Common.PopupMessage).Value)) { MessageBox.Show(Message, severity.ToString(), MessageBoxButton.OK); } this.Visibility = string.IsNullOrEmpty(Message) ? Visibility.Collapsed : Visibility.Visible; } } }
public async Task PorlingMessagesAsync(CancellationToken cancellationToken) { while (cancellationToken.IsCancellationRequested == false) { await Task.Delay(10000, cancellationToken); // upload 10s each to reduce request count to Azure. var queue = Messages?.Invoke(); List <SyslogMessageEventArgs> chunk; lock (queue) { chunk = queue.ToList(); queue.Clear(); } if (chunk.Count < 1) { continue; } var recs = new List <LogRecord>(); foreach (var ev in chunk) { // <189>[INSPECT] LAN2[out][101100] TCP 192.168.20.3:54874 > 172.217.25.193:443 (2020/01/23 14:12:42) // <190>[NAT(1000):LAN2] Released UDP 172.16.20.3.44249 <-> 192.168.20.254.10708 ==> 172.16.20.1.53 var rec = new LogRecord(); var pristr = StrUtil.LeftOn(ev.Message, "^<[0-9]+>"); if (pristr.Length > 2) { // Priority = facility * 8 + severity level ex. 190 = 23*8+6 var pri = int.Parse(StrUtil.Mid(pristr, 1, pristr.Length - 2)); rec.Facility = Facilities.GetValueOrDefault(pri / 8, "n/a"); rec.SeverityLevel = SeverityLevels.GetValueOrDefault(pri % 8, "n/a"); } rec.EventTime = ev.EventUtcTime; rec.HostIP = ev.Remote.Address.ToString(); rec.HostName = /* Dns.GetHostEntry(ev.Remote.Address)?.HostName ?? */ ev.Remote.Address.ToString(); // Do not use Dns.GetHostEntry because of block 5 seconds each for local IPs. rec.Computer = Environment.MachineName; rec.SyslogMessage = StrUtil.MidSkip(ev.Message, "^<[0-9]+>").TrimStart(' ', '\t', '\r', '\n', '\b'); recs.Add(rec); } var jsonStr = JsonConvert.SerializeObject(recs, new IsoDateTimeConverter()); var datestring = DateTime.UtcNow.ToString("r"); var jsonBytes = Encoding.UTF8.GetBytes(jsonStr); var stringToHash = "POST\n" + jsonBytes.Length + "\napplication/json\n" + "x-ms-date:" + datestring + "\n/api/logs"; var hashedString = BuildSignature(stringToHash, Key1); var signature = "SharedKey " + WorkspaceID + ":" + hashedString; PostData(signature, datestring, jsonStr); } }
/// <summary> /// Gets a string representation of a provided severity level. /// </summary> /// <param name="severityLevel">The severity level to get a string representation of.</param> /// <returns>The string representation of the severity level, or an empty string if unknown.</returns> static public string GetSeverityLevelString(SeverityLevels severityLevel) { switch (severityLevel) { case SeverityLevels.Error: return("Error"); case SeverityLevels.Information: return("Information"); case SeverityLevels.Warning: return("Warning"); default: return(""); } }
public LogEntry(string message, Exception ex, string assemblyName) { if (message.Length > 0) { this.message = string.Format("{0}\r\n{1}", message, ErrorDispatcher.GetErrorMessageForException(ex, true)); } else { this.message = ErrorDispatcher.GetErrorMessageForException(ex, true); } // This is already an application non-recoverable error. severityLevel = SeverityLevels.Exception; // Stack dump. stackDump = ex.StackTrace; // Store the assemblyy name. this.assemblyName = assemblyName; GetAppName(); }
internal static List<string> ReadLogFileLines(SeverityLevels filter, string logFile, int lineCount, bool lastRows) { List<string> lines = new List<string>(); if (!string.IsNullOrEmpty(logFile)) { using (FileStream fs = new FileStream(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { long size = fs.Length; if (size > 1024 * 1024) { // Jump to last rows in log file fs.Seek(-1024 * 1024, SeekOrigin.End); } using (StreamReader sr = new StreamReader(fs)) { bool discardSublines = false; while (!sr.EndOfStream) { string line = sr.ReadLine(); if (line != null) { // Analyze line if (!line.StartsWith("~~") && !discardSublines) { lines.Add(line); } else { string[] fields = line.Split(new char[] { '|', '~' }, StringSplitOptions.RemoveEmptyEntries); if (fields.Length >= (int)LogLineFields.FieldCount) { string field = fields[(int)LogLineFields.EntryType]; SeverityLevels entryType = (SeverityLevels)Enum.Parse(typeof(SeverityLevels), field); if ((filter & entryType) == entryType) { lines.Add(line); discardSublines = false; } else { discardSublines = true; } } } } } } } if (lineCount < 1) { return lines; } else { lineCount = Math.Min(lineCount, lines.Count); if (lastRows) { return lines.GetRange(lines.Count - lineCount, lineCount); } else { return lines.GetRange(0, lineCount); } } } return lines; }
public static List<string> GetCurrentLogFileLines(SeverityLevels filter) { return GetCurrentLogFileLines(filter, 0); }
public static List <string> GetCurrentLogFileLines(SeverityLevels filter, int lineCount) { return(GetCurrentLogFileLines(filter, lineCount, false)); }
public static List <string> GetCurrentLogFileLines(SeverityLevels filter) { return(GetCurrentLogFileLines(filter, 0)); }
public static List <string> GetLogFileLines(SeverityLevels filter, string logFile, int lineCount, bool lastRows) { return(LogFileReader.ReadLogFileLines(filter, logFile, lineCount, lastRows)); }
/// <summary> /// Clear the data from the message panel. /// </summary> public void Clear() { if (!DesignerProperties.GetIsInDesignMode(this)) { Severity = SeverityLevels.Undefined; Message = null; this.Visibility = Visibility.Collapsed; } }
/// <summary> /// Publish message to the message panel. /// </summary> /// <param name="msg"></param> public void PublishMessage(XElement msg) { if (!DesignerProperties.GetIsInDesignMode(this)) { if (msg == null) { Clear(); } else { SeverityLevels severity = SeverityLevels.Undefined; string severityString = null; if (msg.Attribute(Common.MessageType) != null) severityString = msg.Attribute(Common.MessageType).Value.ToUpper(); switch (severityString) { case "ERROR": severity = SeverityLevels.Error; break; case "WARNING": severity = SeverityLevels.Warning; break; case "SUCCESS": severity = SeverityLevels.Success; break; default: severity = SeverityLevels.Information; break; } Severity = severity; Message = msg.Value; VisualStateManager.GoToState(this, severity.ToString(), true); if (msg.Attribute(Common.PopupMessage) != null && Common.boolValue(msg.Attribute(Common.PopupMessage).Value)) MessageBox.Show(Message, severity.ToString(), MessageBoxButton.OK); this.Visibility = string.IsNullOrEmpty(Message) ? Visibility.Collapsed : Visibility.Visible; } } }
public static List<string> GetCurrentLogFileLines(SeverityLevels filter, int lineCount, bool lastRows) { string logFile = GetCurrentLogFileName(); lock (_readWriteLock) { return GetLogFileLines(filter, logFile, lineCount, lastRows); } }
public static List<string> GetLogFileLines(SeverityLevels filter, string logFile, int lineCount, bool lastRows) { try { return LogFileReader.ReadLogFileLines(filter, logFile, lineCount, lastRows); } catch { return new List<string>(); } }
private Image GetImage(SeverityLevels level) { try { switch (level) { case SeverityLevels.Automatic: return ImageProvider.GetShell32Icon(Shell32Icon.AutomaticProcess, false); case SeverityLevels.Error: case SeverityLevels.Exception: return ImageProvider.GetUser32Icon(User32Icon.Error, false); case SeverityLevels.Warning: return ImageProvider.GetUser32Icon(User32Icon.Warning, false); case SeverityLevels.Info: return ImageProvider.GetUser32Icon(User32Icon.Information, false); case SeverityLevels.Trace: case SeverityLevels.HeavyTrace: default: return ImageProvider.GetUser32Icon(User32Icon.Application, false); } } catch { } return null; }
public static List<string> GetCurrentLogFileLines(SeverityLevels filter, int lineCount) { return GetCurrentLogFileLines(filter, lineCount, false); }
internal static List <string> ReadLogFileLines(SeverityLevels filter, string logFile, int lineCount, bool lastRows) { List <string> lines = new List <string>(); if (!string.IsNullOrEmpty(logFile)) { using (FileStream fs = new FileStream(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { long size = fs.Length; if (size > 1024 * 1024) { // Jump to last rows in log file fs.Seek(-1024 * 1024, SeekOrigin.End); } using (StreamReader sr = new StreamReader(fs)) { bool discardSublines = false; while (!sr.EndOfStream) { string line = sr.ReadLine(); if (line != null) { // Analyze line if (!line.StartsWith("~~") && !discardSublines) { lines.Add(line); } else { string[] fields = line.Split(new char[] { '|', '~' }, StringSplitOptions.RemoveEmptyEntries); if (fields.Length >= (int)LogLineFields.FieldCount) { string field = fields[(int)LogLineFields.EntryType]; SeverityLevels entryType = (SeverityLevels)Enum.Parse(typeof(SeverityLevels), field); if ((filter & entryType) == entryType) { lines.Add(line); discardSublines = false; } else { discardSublines = true; } } } } } } } if (lineCount < 1) { return(lines); } else { lineCount = Math.Min(lineCount, lines.Count); if (lastRows) { return(lines.GetRange(lines.Count - lineCount, lineCount)); } else { return(lines.GetRange(0, lineCount)); } } } return(lines); }
/// <summary> /// Initializes a new instance of the <see cref="Severity"/> class. /// </summary> /// <param name="type">The type.</param> public Severity(SeverityLevels type) { this.SeverityLevel = (int)type; }