Example #1
0
        public static ExtendedLoggingEvent ConvertLoggingEvent(LoggingEvent loggingEvent, List <RawLayoutParameter> parameters, string application,
                                                               Level environmentVariablesThresholdLevel)
        {
            var extendedLoggingEvent = new ExtendedLoggingEvent(loggingEvent)
            {
                Message     = loggingEvent.RenderedMessage,
                Application = application
            };
            var    variables  = new List <KeyValuePair <string, string> >(100);
            string stackTrace = null;

            if (loggingEvent.Level >= environmentVariablesThresholdLevel)
            {
                variables = GetEnvironmentVariables();
            }
            var otherParameters =
                parameters.FindAll(
                    p => (p.ParameterName != StackTraceText) && (p.LevelMin <= loggingEvent.Level && p.LevelMax >= loggingEvent.Level));

            if (otherParameters.Any())
            {
                foreach (var rawLayoutParameter in otherParameters)
                {
                    var param = new RenderedLayoutParameter(rawLayoutParameter.ParameterName, rawLayoutParameter.Render(loggingEvent));
                    extendedLoggingEvent.EventParameters.Add(param);
                    if (rawLayoutParameter.OmitNull)
                    {
                        if (param.Value != SystemInfo.NullText)
                        {
                            variables.Add(new KeyValuePair <string, string>(param.Name, param.Value));
                        }
                    }
                    else
                    {
                        variables.Add(new KeyValuePair <string, string>(rawLayoutParameter.ParameterName, param.Value));
                    }
                }
            }
            var stackTraceParameter =
                parameters.FirstOrDefault(
                    p => string.Equals(p.ParameterName, StackTraceText, StringComparison.InvariantCultureIgnoreCase));

            if (stackTraceParameter != null)
            {
                stackTrace = stackTraceParameter.Render(loggingEvent);
                if (string.IsNullOrWhiteSpace(stackTrace))
                {
                    if (loggingEvent.ExceptionObject != null && loggingEvent.ExceptionObject.StackTrace != null)
                    {
                        stackTrace = loggingEvent.ExceptionObject.StackTrace;
                    }
                    else
                    {
                        stackTrace = loggingEvent.LocationInformation.FullInfo;
                    }
                }
            }
            extendedLoggingEvent.StackTrace = stackTrace;
            extendedLoggingEvent.Variables  = variables;
            return(extendedLoggingEvent);
        }
 /// <summary>
 ///     Extension point for ExtendedAppenderSkeleton
 /// </summary>
 /// <param name="extendedLoggingEvent"></param>
 //TODO: Abstract
 protected virtual void AppendExtended(ExtendedLoggingEvent extendedLoggingEvent)
 {
 }