protected override void ProcessRecord() { if (Util.IsPaused) return; var logger = Util.GetLogger(); if (logger == null) throw new NullReferenceException("logger"); object state = null; if (this.Message != null) { if (this.Message is string) { state = new FormattedLogValues(this.Message as string, this.MessageArgs ?? new object[0]); } else { state = this.Message; } } logger.Log(this.Level, this.EventId, state, this.Exception, Util.Formatter); base.ProcessRecord(); }
public void LogValues_With_UnbalancedBraces(string format) { Assert.Throws<FormatException>(() => { var logValues = new FormattedLogValues(format); logValues.ToString(); }); }
public void LogValues_With_Basic_Types(string expected, string format, object[] args) { var logValues = new FormattedLogValues(format, args); Assert.Equal(expected, logValues.ToString()); // Original format is expected to be returned from GetValues. Assert.Equal(format, logValues.GetValues().First(v => v.Key == "{OriginalFormat}").Value); }
public void LogValues_With_DateTime(string expected, string format) { var dateTime = new DateTime(2015, 1, 1, 1, 1, 1); var logValues = new FormattedLogValues(format, new object[] { dateTime, dateTime }); Assert.Equal(expected, logValues.ToString()); // Original format is expected to be returned from GetValues. Assert.Equal(format, logValues.GetValues().First(v => v.Key == "{OriginalFormat}").Value); }
public void DoSomething(int input) { var values = new FormattedLogValues("Starting to do something with input: {0}", input); _logger.LogDebug(values); if (input >= -1 && input <= 1) { _logger.LogInformation("Input of {0} is within the optimal range.", input); } else if (input > 10) { _logger.LogWarning("Input of {0} is greater than the typical range.", input); } else if (input < -10) { _logger.LogError("Input of {0} is less than the typical range.", input); } _logger.LogDebug("Finished doing something with input: {0}", input); }
public void FormatsEnumerableValues(string messageFormat, object[] arguments, string expected) { var logValues = new FormattedLogValues(messageFormat, arguments); Assert.Equal(expected, logValues.ToString()); }