public static Error BuildError(string message, Error.Types.Level level) { _log(message, level); return(new Error() { Level = level, Message = message, Timestamp = Timestamp.FromDateTime(DateTime.UtcNow) }); }
/// <summary> /// internal log function /// </summary> /// <typeparam name="T">Exception or string</typeparam> /// <param name="msg"></param> /// <param name="level"></param> public static void _log <T>(T msg, Error.Types.Level level) { if (typeof(T) == typeof(Exception)) { var e = msg as Exception; switch (level) { case Error.Types.Level.Error: case Error.Types.Level.Fatal: _logger.Error(e, e?.Message); break; case Error.Types.Level.Info: _logger.Info(e?.Message); break; case Error.Types.Level.Warning: _logger.Warning(e, e?.Message); break; } } else { var message = msg as string; switch (level) { case Error.Types.Level.Error: case Error.Types.Level.Fatal: _logger.Error(message); break; case Error.Types.Level.Info: _logger.Info(message); break; case Error.Types.Level.Warning: _logger.Warning(message); break; } } }