The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LogMessage.cs 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Microsoft.Extensions.Logging;
  2. using System;
  3. using Teknik.Utilities;
  4. namespace Teknik.Logging
  5. {
  6. public class LogMessage
  7. {
  8. public LogLevel Level { get; set; }
  9. public DateTime EntryDate { get; set; }
  10. public string Message { get; set; }
  11. public Exception Exception { get; set; }
  12. public LogMessage()
  13. {
  14. SetDefaults();
  15. }
  16. public void SetDefaults()
  17. {
  18. Level = LogLevel.Information;
  19. EntryDate = DateTime.Now;
  20. Message = string.Empty;
  21. Exception = null;
  22. }
  23. public override string ToString()
  24. {
  25. // Create the full message we want to log
  26. string fullMessage = Message;
  27. if (Exception != null)
  28. {
  29. fullMessage += " | Exception: " + Exception.GetFullMessage(true, true);
  30. }
  31. // We have rotated if needed, so let's write the entry
  32. return string.Format("{0} | {1} | {2}", Level, EntryDate.ToString("yyyy-MM-dd HH:mm:ss.fff"), fullMessage);
  33. }
  34. }
  35. }