Beispiel #1
0
        public async Task WriteLog(HistorianLogItem logItem)
        {
            using (var context = ContextFactory.CreateDbContext(null))
            {
                await context.HistorianLog.AddAsync(new HistorianLogEntity
                {
                    Timestamp  = logItem.Epoch.TimestampMilliseconds,
                    LevelId    = (int)logItem.LogLevel,
                    Category   = logItem.Category,
                    Message    = logItem.Message,
                    Exception  = logItem.Exception != null ? logItem.Exception.ToString() : null,
                    ExchangeId = logItem.Exchange != null ? (int)logItem.Exchange : (int?)null,
                    SymbolId   = logItem.SymbolCode != null ? (int)logItem.SymbolCode : (int?)null,
                    Protocol   = logItem.Protocol
                });

                await context.SaveChangesAsync();
            }
        }
Beispiel #2
0
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            if (!ValidCategory())
            {
                return;
            }

            var logItem = new HistorianLogItem
            {
                Epoch      = Epoch.Now,
                LogLevel   = logLevel,
                Category   = CategoryName,
                Message    = formatter(state, exception),
                Exception  = exception,
                Exchange   = State.ContainsKey("Exchange") ? (ExchangeEnum)State["Exchange"] : (ExchangeEnum?)null,
                SymbolCode = State.ContainsKey("SymbolCode") ? (SymbolCodeEnum)State["SymbolCode"] : (SymbolCodeEnum?)null,
                Worker     = State.ContainsKey("Worker") ? (string)State["Worker"] : null,
                Protocol   = State.ContainsKey("Protocol") ? (string)State["Protocol"] : null
            };

            LoggerProvider.Enqueue(logItem);
        }
 public void Enqueue(HistorianLogItem item)
 {
     Queue.Enqueue(item);
 }