当前位置: 首页>>代码示例>>C#>>正文


C# LogEvent.RenderMessage方法代码示例

本文整理汇总了C#中Serilog.Events.LogEvent.RenderMessage方法的典型用法代码示例。如果您正苦于以下问题:C# LogEvent.RenderMessage方法的具体用法?C# LogEvent.RenderMessage怎么用?C# LogEvent.RenderMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Serilog.Events.LogEvent的用法示例。


在下文中一共展示了LogEvent.RenderMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateFromLogEvent

        public static EventBuilder CreateFromLogEvent(this ExceptionlessClient client, LogEvent log)
        {
            var builder = log.Exception != null
                ? client.CreateException(log.Exception)
                : client.CreateLog(log.GetSource(), log.RenderMessage(), log.GetLevel());

            builder.Target.Date = log.Timestamp;
            if (log.Level == LogEventLevel.Fatal)
                builder.MarkAsCritical();

            if (!String.IsNullOrWhiteSpace(log.RenderMessage()))
                builder.SetMessage(log.RenderMessage());

            return builder;
        }
开发者ID:jamie94bc,项目名称:serilog-sinks-exceptionless,代码行数:15,代码来源:ExceptionlessClientExtensions.cs

示例2: CreateLogglyEvent

        private LogglyEvent CreateLogglyEvent(LogEvent logEvent)
        {
            var logglyEvent = new LogglyEvent();

            var isHttpTransport = LogglyConfig.Instance.Transport.LogTransport == LogTransport.Https;
            logglyEvent.Syslog.Level = ToSyslogLevel(logEvent);

            foreach (var key in logEvent.Properties.Keys)
            {
                var propertyValue = logEvent.Properties[key];
                var simpleValue = LogglyPropertyFormatter.Simplify(propertyValue);
                logglyEvent.Data.AddIfAbsent(key, simpleValue);
            }

            logglyEvent.Data.AddIfAbsent("Message", logEvent.RenderMessage(_formatProvider));

            if (isHttpTransport)
            {
                // syslog will capture these via the header
                logglyEvent.Data.AddIfAbsent("Level", logEvent.Level.ToString());
            }

            if (logEvent.Exception != null)
            {
                logglyEvent.Data.AddIfAbsent("Exception", logEvent.Exception);
            }
            return logglyEvent;
        }
开发者ID:joneal,项目名称:serilog-sinks-loggly,代码行数:28,代码来源:LogglySink.cs

示例3: FormatInternal

 private void FormatInternal(LogEvent logEvent, TextWriter output)
 {
     if (logEvent == null)
         throw new ArgumentNullException("logEvent");
     if (output == null)
         throw new ArgumentNullException("output");
     if (!_omitEnclosingObject)
         output.Write("{");
     var precedingDelimiter1 = "";
     WriteJsonProperty("Timestamp", logEvent.Timestamp, ref precedingDelimiter1, output);
     WriteJsonProperty("Level", logEvent.Level, ref precedingDelimiter1, output);
     WriteJsonProperty("Message", logEvent.RenderMessage(), ref precedingDelimiter1, output);
     WriteJsonProperty("MessageTemplate", logEvent.MessageTemplate.Text, ref precedingDelimiter1, output);
     if (logEvent.Exception != null)
         WriteJsonProperty("Exception", logEvent.Exception, ref precedingDelimiter1, output);
     if (logEvent.Properties.Count != 0)
     {
         output.Write(",\"Properties\":{");
         var precedingDelimiter2 = "";
         foreach (KeyValuePair<string, LogEventPropertyValue> keyValuePair in logEvent.Properties)
             WriteJsonProperty(keyValuePair.Key, keyValuePair.Value, ref precedingDelimiter2, output);
         output.Write("}");
     }
     if (_omitEnclosingObject)
         return;
     output.Write("}");
 }
开发者ID:droyad,项目名称:SbManager,代码行数:27,代码来源:CustomLogJsonFormatter.cs

示例4: Emit

        public void Emit(LogEvent logEvent)
        {
            var loggerName = "Default";

            LogEventPropertyValue sourceContext;
            if (logEvent.Properties.TryGetValue(Constants.SourceContextPropertyName, out sourceContext))
            {
                var sv = sourceContext as ScalarValue;
                if (sv?.Value is string)
                {
                    loggerName = (string) sv.Value;
                }
            }

            var level = MapLogLevel(logEvent);
            var message = logEvent.RenderMessage(_formatProvider);
            var exception = logEvent.Exception;

            var nlogEvent = new LogEventInfo(level, loggerName, message)
            {
                Exception = exception
            };

            foreach (var property in logEvent.Properties)
            {
                var sv = property.Value as ScalarValue;
                var format = (sv?.Value is string) ? "l" : null;

                nlogEvent.Properties[property.Key] = property.Value.ToString(format, null);
            }

            var logger = LogManager.GetLogger(loggerName);
            logger.Log(nlogEvent);
        }
开发者ID:phoenixx,项目名称:AzureToolkit,代码行数:34,代码来源:NLogSink.cs

示例5: Emit

        /// <summary>
        /// Emit the provided log event to the sink.
        /// </summary>
        /// <param name="logEvent">The log event to write.</param>
        public void Emit(LogEvent logEvent)
        {
            var renderedMessage = logEvent.RenderMessage(_formatProvider);
            
            // take logEvent and use it for the corresponding ITelemetry counterpart
            if (logEvent.Exception != null)
            {
                var exceptionTelemetry = new ExceptionTelemetry(logEvent.Exception)
                {
                    SeverityLevel = logEvent.Level.ToSeverityLevel(),
                    HandledAt = ExceptionHandledAt.UserCode,
                    Timestamp = logEvent.Timestamp
                };
                
                // write logEvent's .Properties to the AI one
                ForwardLogEventPropertiesToTelemetryProperties(exceptionTelemetry, logEvent, renderedMessage);

                _telemetryClient.TrackException(exceptionTelemetry);
            }
            else
            {
                var eventTelemetry = new EventTelemetry(logEvent.MessageTemplate.Text)
                {
                    Timestamp = logEvent.Timestamp
                };
                
                // write logEvent's .Properties to the AI one
                ForwardLogEventPropertiesToTelemetryProperties(eventTelemetry, logEvent, renderedMessage);
                
                _telemetryClient.TrackEvent(eventTelemetry);
            }
        }
开发者ID:alexvaluyskiy,项目名称:serilog-sinks-applicationinsights,代码行数:36,代码来源:ApplicationInsightsSink.cs

示例6: Emit

        /// <summary>
        /// Emit the provided log event to the sink.
        /// </summary>
        /// <param name="logEvent">The log event to write.</param>
        public void Emit(LogEvent logEvent)
        {
            var error = logEvent.Exception != null ? new Error(logEvent.Exception) : new Error();

            error.Message = logEvent.RenderMessage(_formatProvider);
            error.Time = logEvent.Timestamp.DateTime;

            _errorLog.Log(error);
        }
开发者ID:BugBusted,项目名称:serilog,代码行数:13,代码来源:ElmahIOSink.cs

示例7: Emit

        public void Emit(LogEvent logEvent)
        {
            var text = logEvent.RenderMessage();

            using (var writer = new StringWriter())
            {
                new ElasticsearchJsonFormatter().Format(logEvent, writer);
                var str = writer.ToString();
                //Console.WriteLine(str);
            }
        }
开发者ID:xorandor,项目名称:ElasticLoggingDemo,代码行数:11,代码来源:SerilogLogger.cs

示例8: Emit

 public void Emit(LogEvent logEvent)
 {
     LogEventPropertyValue contextValue;
     if (!logEvent.Properties.TryGetValue(Constants.SourceContextPropertyName, out contextValue))
     {
         return;
     }
     var scalar = contextValue as ScalarValue;
     if (scalar == null) return;
     var @group = (string)scalar.Value;
     _context.Clients.Group(@group).NewMessage(new StatusMessage { Message = logEvent.RenderMessage(_formatProvider) });
 }
开发者ID:eugene-goldberg,项目名称:StandaloneServiceTemplate,代码行数:12,代码来源:SignalRLogSink.cs

示例9: Emit

        /// <summary>
        /// Emit the provided log event to the sink.
        /// </summary>
        /// <param name="logEvent">The log event to write.</param>
        public void Emit(LogEvent logEvent)
        {
            var message = new Message(logEvent.RenderMessage(_formatProvider))
            {
                Severity = LevelToSeverity(logEvent),
                DateTime = logEvent.Timestamp.DateTime.ToUniversalTime(),
                Detail = logEvent.Exception != null ? logEvent.Exception.ToString() : null,
                Data = PropertiesToData(logEvent),
            };

            _logger.Log(message);
        }
开发者ID:modulexcite,项目名称:serilog-sinks-elmahio,代码行数:16,代码来源:ElmahIOSink.cs

示例10: Emit

        /// <summary>
        /// Emit the provided log event to the sink.
        /// </summary>
        /// <param name="logEvent">The log event to write.</param>
        public void Emit(LogEvent logEvent)
        {
            //Include the log level as a tag.
            var tags = _tags.Concat(new []{logEvent.Level.ToString()}).ToList();

            var properties = logEvent.Properties
                         .Select(pv => new { Name = pv.Key, Value = RaygunPropertyFormatter.Simplify(pv.Value) })
                         .ToDictionary(a => a.Name, b => b.Value);

            // Add the message 
            properties.Add("RenderedLogMessage", logEvent.RenderMessage(_formatProvider));
            properties.Add("LogMessageTemplate", logEvent.MessageTemplate.Text);

            // Create new message
            var raygunMessage = new RaygunMessage
                                {
                                    OccurredOn = logEvent.Timestamp.UtcDateTime
                                };

            // Add exception when available
            if (logEvent.Exception != null)
                raygunMessage.Details.Error = new RaygunErrorMessage(logEvent.Exception);

            // Add user when requested
            if (!String.IsNullOrWhiteSpace(_userNameProperty) &&
                logEvent.Properties.ContainsKey(_userNameProperty) &&
                logEvent.Properties[_userNameProperty] != null)
            {
                raygunMessage.Details.User = new RaygunIdentifierMessage(logEvent.Properties[_userNameProperty].ToString());
            }

            // Add version when requested
            if (!String.IsNullOrWhiteSpace(_applicationVersionProperty) &&
                logEvent.Properties.ContainsKey(_applicationVersionProperty) &&
                logEvent.Properties[_applicationVersionProperty] != null)
            {
                raygunMessage.Details.Version = logEvent.Properties[_applicationVersionProperty].ToString();
            }

            // Build up the rest of the message
            raygunMessage.Details.Environment = new RaygunEnvironmentMessage();
            raygunMessage.Details.Tags = tags;
            raygunMessage.Details.UserCustomData = properties;
            raygunMessage.Details.MachineName = Environment.MachineName;
          
            if (HttpContext.Current != null)
                raygunMessage.Details.Request = new RaygunRequestMessage(HttpContext.Current.Request, null);

            // Submit
            _client.SendInBackground(raygunMessage);

        }
开发者ID:BugBusted,项目名称:serilog,代码行数:56,代码来源:RaygunSink.cs

示例11: LogEventEntity

 /// <summary>
 /// Create a log event entity from a Serilog <see cref="LogEvent"/>.
 /// </summary>
 /// <param name="log">The event to log</param>
 /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
 public LogEventEntity(LogEvent log, IFormatProvider formatProvider)
 {
     Timestamp = log.Timestamp.ToUniversalTime().DateTime;
     PartitionKey = string.Format("0{0}", Timestamp.Ticks);
     RowKey = GetValidRowKey(string.Format("{0}|{1}", log.Level, log.MessageTemplate.Text));
     MessageTemplate = log.MessageTemplate.Text;
     Level = log.Level.ToString();
     Exception = log.Exception != null ? log.Exception.ToString() : null;
     RenderedMessage = log.RenderMessage(formatProvider);
     var s = new StringWriter();
     new JsonFormatter(closingDelimiter: "", formatProvider: formatProvider).Format(log, s);
     Data = s.ToString();
 }
开发者ID:JustGiving,项目名称:serilog,代码行数:18,代码来源:LogEventEntity.cs

示例12: LogEventEntity

 /// <summary>
 /// Construct a new <seealso cref="LogEventEntity"/>.
 /// </summary>
 public LogEventEntity(LogEvent logEvent, IFormatProvider formatProvider)
 {
     TimeStamp = logEvent.Timestamp;
     Exception = logEvent.Exception;
     MessageTemplate = logEvent.MessageTemplate.Text;
     Level = logEvent.Level;
     RenderedMessage = logEvent.RenderMessage(formatProvider);
     Properties = new Dictionary<string, LogEventProperty>();
     foreach (var pair in logEvent.Properties)
     {
         Properties.Add(pair);
     }
 }
开发者ID:nickvane,项目名称:serilog,代码行数:16,代码来源:LogEventEntity.cs

示例13: EmitAsync

        async Task EmitAsync(LogEvent logEvent)
        {
            if (hubConnection.State == ConnectionState.Disconnected)
                await hubConnection.Start();


            var liveEvent = new LiveEvent
            {
                Timestamp = logEvent.Timestamp,
                Level = (LiveEventLevel)logEvent.Level,
                Message = logEvent.RenderMessage(),
                Template = logEvent.MessageTemplate.Text,
            };

            await hubProxy.Invoke<LiveEvent>("log", liveEvent);
        }
开发者ID:NicolasFatoux,项目名称:LiveLog,代码行数:16,代码来源:LiveLogSink.cs

示例14: CreateEntityWithProperties

		/// <summary>
		/// Creates a DynamicTableEntity for Azure Storage, given a Serilog <see cref="LogEvent"/>.Properties
		/// are stored as separate columns.
		/// </summary>
		/// <param name="logEvent">The event to log</param>
		/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
		/// <param name="additionalRowKeyPostfix">Additional postfix string that will be appended to row keys</param>
		/// <returns></returns>
		public static DynamicTableEntity CreateEntityWithProperties(LogEvent logEvent, IFormatProvider formatProvider, string additionalRowKeyPostfix)
		{
			var tableEntity = new DynamicTableEntity();

			tableEntity.PartitionKey = GenerateValidPartitionKey(logEvent);
			tableEntity.RowKey = GenerateValidRowKey(logEvent, additionalRowKeyPostfix);
			tableEntity.Timestamp = logEvent.Timestamp;

			var dynamicProperties = tableEntity.Properties;

			dynamicProperties.Add("MessageTemplate", new EntityProperty(logEvent.MessageTemplate.Text));
			dynamicProperties.Add("Level", new EntityProperty(logEvent.Level.ToString()));
			dynamicProperties.Add("RenderedMessage", new EntityProperty(logEvent.RenderMessage(formatProvider)));

			if (logEvent.Exception != null)
			{
				dynamicProperties.Add("Exception", new EntityProperty(logEvent.Exception.ToString()));
			}


			List<KeyValuePair<ScalarValue, LogEventPropertyValue>> additionalData = null;
			int count = dynamicProperties.Count;
			foreach (var logProperty in logEvent.Properties)
			{
				if (count++ < _maxNumberOfPropertiesPerRow - 1)
				{
					dynamicProperties.Add(logProperty.Key, AzurePropertyFormatter.ToEntityProperty(logProperty.Value, null, formatProvider));
				}
				else
				{
					if (additionalData == null)
					{
						additionalData = new List<KeyValuePair<ScalarValue, LogEventPropertyValue>>();
					}
					additionalData.Add(new KeyValuePair<ScalarValue, LogEventPropertyValue>(new ScalarValue(logProperty.Key), logProperty.Value));
				}
			}

			if (additionalData != null)
			{
				dynamicProperties.Add("AggregatedProperties", AzurePropertyFormatter.ToEntityProperty(new DictionaryValue(additionalData), null, formatProvider));
			}

			return tableEntity;
		}
开发者ID:Sensarg22,项目名称:serilog-sinks-azuretablestorage,代码行数:53,代码来源:AzureTableStorageEntityFactory.cs

示例15: Emit

        /// <summary>
        /// Emit the provided log event to the sink.
        /// </summary>
        /// <param name="logEvent">The log event to write.</param>
        public void Emit(LogEvent logEvent)
        {
            // Create a new FluentEvent for Loggr based on the exception or the properties.
            var ev = logEvent.Exception != null
                ? global::Loggr.Events.CreateFromException(logEvent.Exception)
                : global::Loggr.Events.CreateFromVariable(logEvent.Properties);

            ev.Text(logEvent.RenderMessage(_formatProvider));
            ev.AddTags(logEvent.Level.ToString());

            if (!String.IsNullOrWhiteSpace(_userNameProperty) && logEvent.Properties.ContainsKey(_userNameProperty) && logEvent.Properties[_userNameProperty] != null)
            {
                ev.User(logEvent.Properties[_userNameProperty].ToString());
            }

            ev.UseLogClient(_client);
            ev.Post(true);
        }
开发者ID:nberardi,项目名称:serilog,代码行数:22,代码来源:LoggrSink.cs


注:本文中的Serilog.Events.LogEvent.RenderMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。