Example #1
1
        public void TraceEnter(string methodName, Tuple <string, string>[] methodParameters, string[] paramNames, object[] paramValues)
        {
            if (_logger.IsEnabled(LogEventLevel.Verbose))
            {
                var props = new List <LogEventProperty>();

                if (paramNames != null)
                {
                    for (var i = 0; i < paramNames.Length; i++)
                    {
                        if (paramValues[i] != null && ShouldDestructure(paramValues[i].GetType()))
                        {
                            LogEventProperty prop;
                            if (_logger.BindProperty(paramNames[i], paramValues[i] ?? NullString, true, out prop))
                            {
                                props.Add(prop);
                            }
                        }
                        else
                        {
                            props.Add(new LogEventProperty(paramNames[i], new ScalarValue(_renderParameterMethod(paramValues[i], NullString))));
                        }
                    }
                }

                var properties = new List <LogEventProperty>
                {
                    new LogEventProperty("MethodName", new ScalarValue(methodName)),
                    new LogEventProperty("CallingParameters", new StructureValue(props))
                };

                var logEvent = new LogEvent(DateTimeOffset.Now, LogEventLevel.Verbose, null, _traceEnterTemplate, properties);

                logEvent.AddPropertyIfAbsent(new LogEventProperty("TraceType", new ScalarValue("Enter")));
                logEvent.AddPropertyIfAbsent(new LogEventProperty("ClassName", new ScalarValue(_typeName)));
                logEvent.AddPropertyIfAbsent(new LogEventProperty("Namespace", new ScalarValue(_namespaceName)));

                _logger.Write(logEvent);
            }
        }