示例#1
0
        private List <ObserverLogEntry> GetObserverErrWarnLogEntryListFromLogText(string observerLogText)
        {
            var reportItems = new List <ObserverLogEntry>();
            var logArray    = observerLogText.Split("\r\n", StringSplitOptions.RemoveEmptyEntries);

            foreach (var item in logArray)
            {
                if (!item.Contains("--") &&
                    (!item.Contains("WARN") || !item.Contains("ERROR")))
                {
                    continue;
                }

                string[] arr = item.Split("--", StringSplitOptions.RemoveEmptyEntries);

                var logReport = new ObserverLogEntry
                {
                    Date        = arr[0],
                    HealthState = arr[1],
                    Message     = arr[2].Trim('\n'),
                };

                reportItems.Add(logReport);
            }

            return(reportItems);
        }
示例#2
0
        private string GetObserverErrWarnLogEntryListFromLogText(string observerLogText)
        {
            if (string.IsNullOrEmpty(observerLogText))
            {
                ObserverLogEntry ret = new ObserverLogEntry
                {
                    Date        = DateTime.UtcNow.ToString("MM-dd-yyyy HH:mm:ss.ffff", CultureInfo.InvariantCulture),
                    HealthState = "Ok",
                    Message     = string.Empty,
                };

                return(System.Text.Json.JsonSerializer.Serialize(ret));
            }

            string[] logArray = observerLogText.Split($"{Environment.NewLine}", StringSplitOptions.RemoveEmptyEntries);
            string   entry    = "[";

            foreach (string item in logArray)
            {
                if (!item.Contains("--") &&
                    (!item.Contains("WARN") || !item.Contains("ERROR")))
                {
                    continue;
                }

                string[] arr = item.Split("--", StringSplitOptions.RemoveEmptyEntries);

                // Note: This is already Json (it's a serialized instance of FO's TelemetryData type)..
                entry += arr[2][arr[2].IndexOf("{")..] + ",";