Beispiel #1
0
        private bool IsLogEventMutableSafe(LogEventInfo logEvent)
        {
            if (logEvent.Exception == null)
            {
                if (!logEvent.HasProperties)
                {
                    return(true); // No mutable state, no need to precalculate
                }
                var properties = logEvent.CreateOrUpdatePropertiesInternal(false);
                if (properties == null || properties.Count == 0)
                {
                    return(true); // No mutable state, no need to precalculate
                }
                if (properties.Count <= 5)
                {
                    bool immutableProperties = true;
                    foreach (var property in properties)
                    {
                        if (Convert.GetTypeCode(property.Value) == TypeCode.Object)
                        {
                            immutableProperties = false;
                            break;
                        }
                    }
                    if (immutableProperties)
                    {
                        return(true); // No mutable state, no need to precalculate
                    }
                }
            }

            return(false);
        }
Beispiel #2
0
 private void AppendToBuilder(LogEventInfo logEvent, StringBuilder builder)
 {
     logEvent.Message.Render(logEvent.FormatProvider ?? CultureInfo.CurrentCulture, logEvent.Parameters, _forceTemplateRenderer, builder, out var messageTemplateParameterList);
     logEvent.CreateOrUpdatePropertiesInternal(false, messageTemplateParameterList ?? ArrayHelper.Empty <MessageTemplateParameter>());
 }