Ejemplo n.º 1
0
 /// <summary>
 /// Process item from the blocking queue
 /// </summary>
 /// <param name="logitem"></param>
 private static void ProcessChartQueueItem(ChartLogItem logitem)
 {
     try
     {
         if (logitem.Message != string.Empty)
         {
             FileWriteAsync(_fileLocation + "GS" + logitem.LogBaseName + _fileNameAddOn + _instanceFileName, logitem);
         }
     }
     catch (Exception ex)
     {
         var monitorItem = new MonitorEntry
         {
             Datetime = HiResDateTime.UtcNow,
             Device   = MonitorDevice.Server,
             Category = MonitorCategory.Server,
             Type     = MonitorType.Error,
             Method   = MethodBase.GetCurrentMethod().Name,
             Thread   = Thread.CurrentThread.ManagedThreadId,
             Message  = $" {ex.Message}"
         };
         MonitorLog.LogToMonitor(monitorItem);
         IsRunning = false;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Send entries to a file async
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="logitem"></param>
        /// <param name="append"></param>
        private static async void FileWriteAsync(string filePath, ChartLogItem logitem, bool append = true)
        {
            await _lockFile.WaitAsync();

            try
            {
                Directory.CreateDirectory(Path.GetDirectoryName(filePath) ?? throw new InvalidOperationException());
                using (var stream = new FileStream(filePath, append ? FileMode.Append : FileMode.Create, FileAccess.Write, FileShare.None, 4096, true))
                    using (var sw = new StreamWriter(stream))
                    {
                        var str = $"{(int)logitem.ChartType},{(int)logitem.LogCode},{logitem.Message}";
                        await sw.WriteLineAsync(str);
                    }
            }
            catch (IOException ex)
            {
                var monitorItem = new MonitorEntry
                {
                    Datetime = HiResDateTime.UtcNow,
                    Device   = MonitorDevice.Server,
                    Category = MonitorCategory.Server,
                    Type     = MonitorType.Error,
                    Method   = MethodBase.GetCurrentMethod().Name,
                    Thread   = Thread.CurrentThread.ManagedThreadId,
                    Message  = $" {ex.Message}"
                };
                MonitorLog.LogToMonitor(monitorItem);
            }
            finally
            {
                _lockFile.Release();
            }
        }
Ejemplo n.º 3
0
        public static void LogSeries(string basename, ChartType type, string series, string message)
        {
            if (!IsRunning)
            {
                return;
            }
            var str           = $"{HiResDateTime.UtcNow.ToLocalTime():yyyy-MM-dd HH:mm:ss.fff},{series},{message}";
            var chartsLogItem = new ChartLogItem {
                LogBaseName = basename, ChartType = type, LogCode = ChartLogCode.Series, Message = str
            };

            AddEntry(chartsLogItem);
        }
Ejemplo n.º 4
0
        public static void LogPoint(string basename, ChartType type, PointModel point)
        {
            if (!IsRunning)
            {
                return;
            }
            var str           = $"{point.DateTime.ToLocalTime():yyyy-MM-dd HH:mm:ss.fff},{point.Value},{point.Set}";
            var chartsLogItem = new ChartLogItem {
                LogBaseName = basename, ChartType = type, LogCode = ChartLogCode.Point, Message = str
            };

            AddEntry(chartsLogItem);
        }
Ejemplo n.º 5
0
        public static void LogData(string basename, ChartType type, string key, string value)
        {
            if (!IsRunning)
            {
                return;
            }
            var str           = $"{HiResDateTime.UtcNow.ToLocalTime():yyyy-MM-dd HH:mm:ss.fff},{key},{value}";
            var chartsLogItem = new ChartLogItem {
                LogBaseName = basename, ChartType = type, LogCode = ChartLogCode.Data, Message = str
            };

            AddEntry(chartsLogItem);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// adds a item to a blocking queue
 /// </summary>
 /// <param name="logitem"></param>
 private static void AddEntry(ChartLogItem logitem)
 {
     _chartBlockingCollection.TryAdd(logitem);
 }