/// <summary>
        /// see IEventStoreConnector for documentation
        /// </summary>
        /// <param name="evt"></param>
        /// <returns></returns>
        public Guid Submit(LogEvent evt,EventOptions options=null)
        {
            var s = JsonConvert.SerializeObject(evt, Formatting.Indented, new JsonSerializerSettings()
            {
                 ReferenceLoopHandling = ReferenceLoopHandling.Serialize
            });

            var logger = getLogger(evt);
            var nLogLevel = getLogLevel(evt);

            if (!logger.IsEnabled(nLogLevel)) return evt.UUID;

            logger.Log((LogEventInfo)mapper(evt, nLogLevel));

            return evt.UUID;
        }
Example #2
0
 /// <summary>
 /// Writes a hydrated event to configured event store
 /// </summary>
 /// <param name="evt">Event to persist to logger's event store</param>
 public void Write(LogEvent evt)
 {
     _loggerConfig.EventStoreConnector.Submit(evt);
 }
 private LogLevel getLogLevel(LogEvent evt)
 {
     switch (evt.EventType)
     {
         case TraceEventType.Critical: return LogLevel.Fatal;
         case TraceEventType.Error: return LogLevel.Error;
         case TraceEventType.Warning: return LogLevel.Warn;
         case TraceEventType.Information: return LogLevel.Info;
         case TraceEventType.Verbose: return LogLevel.Trace;
         case TraceEventType.Start: return LogLevel.Debug;
         case TraceEventType.Stop: return LogLevel.Debug;
         case TraceEventType.Resume: return LogLevel.Debug;
         case TraceEventType.Suspend: return LogLevel.Debug;
         case TraceEventType.Transfer: return LogLevel.Debug;
     }
     return LogLevel.Off;
 }
        private LogEventInfo mapper(LogEvent evt, LogLevel nLogLevel)
        {
            var retVal = new LogEventInfo(nLogLevel, evt.EventSource, evt.Message);
            retVal.TimeStamp = evt.TimeStamp;
            retVal.Properties.Add("TimeStamp", evt.TimeStamp);
            retVal.Properties.Add("Message", evt.Message);
            retVal.Properties.Add("UUID", evt.UUID);
            retVal.Properties.Add("Application", evt.Application);
            retVal.Properties.Add("Module", evt.Module);

            retVal.Properties.Add("Environment", evt.Environment);
            retVal.Properties.Add("Host", evt.Host);
            retVal.Properties.Add("EventSource", evt.EventSource);
            retVal.Properties.Add("EventType", evt.EventTypeName);
            retVal.Properties.Add("EventTypeId", (int)evt.EventType);

            retVal.Properties.Add("Priority", evt.PriorityName);
            retVal.Properties.Add("PriorityId", (int)evt.Priority);

            if (!string.IsNullOrWhiteSpace(evt.User)) retVal.Properties.Add("User", evt.User);
            if (!string.IsNullOrWhiteSpace(evt.EventCode)) retVal.Properties.Add("EventCode", evt.EventCode);

            retVal.Properties.Add("EventId", evt.EventId);
            if (evt.Exceptions != null && evt.Exceptions.Count > 0)
            {
                for (int exceptionIndex = 0; exceptionIndex < evt.Exceptions.Count; exceptionIndex++)
                {
                    expandException(evt.Exceptions[exceptionIndex], exceptionIndex, retVal.Properties);
                }
            }

            evt.Properties.ForEach(e => retVal.Properties.Add(string.Format("{0}.{1}", e.Group, e.Name), e.Value));
            return retVal;
        }
 private string getLoggerName(LogEvent evt)
 {
     if (!string.IsNullOrWhiteSpace(evt.EventSource)) return evt.EventSource;
     if (!string.IsNullOrWhiteSpace(evt.Application)) return evt.Application;
     return "default";
 }
        private ILoggerBase getLogger(LogEvent evt)
        {
            var loggerName = getLoggerName(evt);

            if (_nlogInstances.ContainsKey(loggerName))
            {
                return _nlogInstances[loggerName];
            }
            lock (listLock)
            {
                if (_nlogInstances.ContainsKey(loggerName))
                {
                    return _nlogInstances[loggerName];
                }

                var nLogger = LogManager.GetLogger(loggerName);
                _nlogInstances[loggerName] = nLogger;
                return nLogger;
            }
        }
Example #7
0
 public void Enqueue(LogEvent evt)
 {
     _queue.TryAdd(evt, Timeout.Infinite, _cancelToken.Token);
 }
Example #8
0
 private void writeEvent(LogEvent evt)
 {
     _options.EventStoreConnector.Submit(evt);
 }
        /// <summary>
        /// Low level method to convert internal LogEventBuilder data into standard
        /// LogEvent the client can use.  Similar in concept to log4Net.Fix()
        /// </summary>
        /// <returns></returns>
        public LogEvent ConvertToEvent()
        {
            var retVal = new LogEvent();
            retVal.Application = this.applicationKey ?? Config.ApplicationName;
            retVal.Module = this._appSubKey ?? Config.ApplicationModule;
            retVal.TimeStamp = this.timeStamp;
            retVal.EventSource = this.loggerName;
            retVal.EventType = this.severity;
            retVal.Host = this.Config.HostName;
            if (!string.IsNullOrWhiteSpace(_messageText))
            {
                retVal.Message = _messageText;
            }
            else
            {
                if (_exceptions != null && _exceptions.Count > 0 && _exceptions[0] != null)
                {
                    retVal.Message = _exceptions[0].BaseException.Message;
                }
            };

            retVal.User = (_userContext != null) ? _userContext.DefaultUser : "******";
            retVal.Environment = this.Config.ActiveEnvironment;
            if (this.priority == default(LogEventPriority))
            {
                retVal.Priority = retVal.EventType.ToPriority();
            }

            if (this._eventId == 0)
            {
                retVal.EventId = (int)retVal.Priority + (int)retVal.EventType;
            }

            retVal.UUID = this.UUID;

            if (this._exceptions != null && this._exceptions.Count > 0)
            {
                retVal.Exceptions = new List<LogException>();
                retVal.Exceptions.AddRange(this._exceptions);
            }

            if (!string.IsNullOrWhiteSpace(this.applicationSubKey))
            {
                retVal.Properties.Add(new LogEventProperty() { Group = "General", Name = "SubKey", Value = this.applicationSubKey });
            }

            retVal.Properties.Add(new LogEventProperty() { Group = "General", Name = "ActivityId", Value = this.activityId.ToString() });
            if (this._reference != null)
            {
                retVal.Properties.Add(new LogEventProperty() { Group = "General", Name = "Reference", Value = JsonConvert.SerializeObject(this._reference, Formatting.Indented) });
            }

            if (this.properties != null && this.properties.Count > 0)
            {
                foreach (var prop in this.properties)
                {
                    retVal.Properties.Add(new LogEventProperty() { Group = "Properties", Name = prop.Key, Value = prop.Value });
                }
            }

            if (this.httpContext != null)
            {
                convertToEvent(retVal.Properties, this.httpContext);
            }
            if (this.machineContext != null)
            {
                convertToEvent(retVal.Properties, this.machineContext);
            }
            if (_userContext != null)
            {
                convertToEvent(retVal.Properties, _userContext);
            }

            retVal.Properties.ForEach(p =>
            {
                p.EventUUID = retVal.UUID;
            });
            return retVal;
        }