Esempio n. 1
0
        public static LogEvent CreateEvent(string sourceName, LogSeverity severity, EventType eventType, string format, object[] parameters)
        {
            var e = new LogEvent(severity, sourceName, DateTime.UtcNow)
            {
                EventType = eventType
            };

            //add error
            Exception error = ExtractError(parameters);

            if (error != null)
            {
                e.AddProperty(KnownProperty.Error, error);
            }

            //enrich
            Enrich(e, L.Config.Enrichers);
#if NETSTANDARD || NET46
            Enrich(e, LogContext.Enrichers?.Values);
#endif

            //message
            FormattedString fs = FormattedString.Parse(format, parameters);
            e.Message          = fs;
            e.FormattedMessage = fs.ToString();
            foreach (var namedParam in fs.NamedParameters)
            {
                e.AddProperty(namedParam.Key, namedParam.Value);
            }

            return(e);
        }
Esempio n. 2
0
      private static void Enrich(LogEvent e, IEnumerable<IEnricher> enrichers)
      {
         if (enrichers == null) return;

         foreach (IEnricher enricher in enrichers)
         {
            string pn;
            object pv;
            enricher.Enrich(e, out pn, out pv);
            if (pn != null)
            {
               e.AddProperty(pn, pv);
            }
         }
      }
Esempio n. 3
0
        internal void Serve(LogSeverity severity, EventType eventType,
                            Dictionary <string, object> properties,
                            string format, params object[] parameters)
        {
            LogEvent e = EventFactory.CreateEvent(_name, severity, eventType, format, parameters);

            if (properties != null && properties.Count > 0)
            {
                foreach (var prop in properties)
                {
                    e.AddProperty(prop.Key, prop.Value);
                }
            }

            SubmitNow(e);
        }