示例#1
0
        private void DoLog(string methodName, LogEventLevel level, Exception exception, string messageTemplate, object[] propertyValues)
        {
            if (propertyValues != null &&
                propertyValues.GetType() != typeof(object[]))
            {
                propertyValues = new object[] { propertyValues }
            }
            ;

            MessageTemplate parsedTemplate;
            IEnumerable <LogEventProperty> boundProperties;

            _logger.BindMessageTemplate(messageTemplate, propertyValues, out parsedTemplate, out boundProperties);

            var logEvent = new LogEvent(DateTimeOffset.Now, level, exception, parsedTemplate, boundProperties);

            logEvent.AddPropertyIfAbsent(new LogEventProperty("MethodName", new ScalarValue(methodName)));
            logEvent.AddPropertyIfAbsent(new LogEventProperty("ClassName", new ScalarValue(_typeName)));

            _logger.Write(logEvent);
        }