本文整理汇总了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;
}
示例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;
}
示例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("}");
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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) });
}
示例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);
}
示例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);
}
示例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();
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}