using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Vrh.OneReport.Lib.Areas.OneReport.Helpers { public class Log { /// /// The available levels of logging. /// public enum LogLevel { None, Error, Warning, Info, Debug } #if (DEBUG) private static LogLevel Level = LogLevel.Debug; private static LogLevel DebugLevel = LogLevel.Debug; #else private static LogLevel Level = LogLevel.Error; private static LogLevel DebugLevel = LogLevel.Error; #endif public static System.Web.Mvc.ModelStateDictionary modelstate; private static List TextToDisplay = new List(); /// /// Sets the log level. /// The new log level. /// public static void SetLogLevel(LogLevel level) { Level = level; } /// /// Logs an error message. /// The text to be logged. /// public static void Error(string text) { if (Level >= LogLevel.Error) { modelstate.AddModelError(string.Empty, text); } } /// /// Logs a warning message. /// The text to be logged. /// public static void Warning(string text) { if (Level >= LogLevel.Warning) { if (DebugLevel >= LogLevel.Warning) TextToDisplay.Add("Warning: " + text); } } /// /// Logs an info message. /// The text to be logged. /// public static void Info(string text) { if (Level >= LogLevel.Info) { if (DebugLevel >= LogLevel.Info) TextToDisplay.Add(text); } } /// /// Logs a debug message. /// The text to be logged. /// public static void Debug(string text) { if (Level >= LogLevel.Debug) { if (DebugLevel >= LogLevel.Debug) TextToDisplay.Add("Debug: " + text); } } /// /// Gets the html message. /// The text in html. /// public static string GetHtmlMessages() { string rv = ""; foreach (var item in TextToDisplay) { if (string.IsNullOrEmpty(rv)) rv = ""; TextToDisplay.Clear(); return rv; } } }