private static void Ejecutar() { var container = Bootstrapper.LoadContainer(); var objJobLogger = new JobLogger(); Console.WriteLine("Ingrese el tipo de mensaje: "); Console.WriteLine("0 - Error"); Console.WriteLine("1 - Warning"); Console.WriteLine("2 - Mensaje"); objJobLogger.Tipo_Mensaje = Console.ReadLine(); Console.WriteLine("Ingrese el mensaje: "); objJobLogger.Mensaje = Console.ReadLine(); using (var scope = container.BeginLifetimeScope()) { var sresolve = scope.Resolve<IJobLoggerAplicacion>(); var obj = new JobLoggerController(sresolve); var statusResponse = obj.Save(objJobLogger); if (statusResponse.Success) Console.WriteLine(DateTime.Now.ToShortDateString() + ": " + statusResponse.Message); else Console.WriteLine(DateTime.Now.ToShortDateString() + ": " + string.Join(string.Empty, statusResponse.Messages)); } Console.ReadLine(); Console.Clear(); Ejecutar(); }
public void TestDataBaseAndFile_MarkWarning() { JobLogger _JobLogger = new JobLogger(true, false, true, true, true, true); Result _Result = _JobLogger.LogMessage("Mensaje de prueba", false, true, false); Assert.NotNull(_Result); Assert.That(_Result.Code, Is.EqualTo((int)Enumerates.Result.Success)); }
public void Test_WithOutSetAnyMarker() { JobLogger _JobLogger = new JobLogger(true, true, true, false, false, false); Result _Result = _JobLogger.LogMessage("mensaje", false, true, false); Assert.NotNull(_Result); Assert.That(_Result.Code, Is.EqualTo((int)Enumerates.Result.Error)); }
public void Given_NullMessage_When_CallingWarning_Then_ReturnNotSuccess() { IJobLogger logger = new JobLogger(_databaseRepository, _fileRepository, _consoleRepository); var success = logger.Warning(InvalidMessage); Assert.IsFalse(success); }
public void WriteErrorTest() { JobLogger C1 = retornarLogger(configLogger.soloErrores); int expectedResponse = 1; Assert.AreEqual(expectedResponse, C1.LogMessage("Error Test", LogType.Error)); }
public void WriteMessageTest() { JobLogger C1 = retornarLogger(configLogger.soloMensajes); int expectedResponse = 1; Assert.AreEqual(expectedResponse, C1.LogMessage("Message Test", LogType.Message)); }
public void WriteWarningTest() { JobLogger C1 = retornarLogger(configLogger.soloWarnings); int expectedResponse = 1; Assert.AreEqual(expectedResponse, C1.LogMessage("Warning Test", LogType.Warning)); }
static void Main(string[] args) { string[] tiposMensajes = { "ERROR", "WARNING", "MESSAGE" }; string[] tiposLogs = { "CONSOLE", "FILE", "BD" }; JobLogger.LogMessage("probando", tiposLogs, tiposMensajes); Console.ReadLine(); }
public void Given_ValidMessage_When_CallingMessage_Then_ReturnSuccess() { IJobLogger logger = new JobLogger(_databaseRepository, _fileRepository, _consoleRepository); var success = logger.Message(ValidMessage); Assert.IsTrue(success); }
static void Main(string[] args) { JobLogger.LogMessage("Hello", LogType.Message); JobLogger.LogMessage("Hello", LogType.Error); JobLogger.LogMessage("Hello", LogType.Warning); Console.ReadLine(); }
public void TestMethod1() { const string message = "Inicio de sesión con éxito"; const bool message2 = true; const bool warning = true; const bool error = true; JobLogger.LogMessage(message, message2, warning, error); }
public void TestMethodFile() { ContentLog con = new ContentLog(true, false, false); con.ContText = "Prueba Mensaje"; con.IdContent = 1; JobLogger job = new JobLogger(); bool resultado = job.GenerateLog(con, true, false, false); }
static void Main(string[] args) { //Run Example var jobLogger = new JobLogger(logToFile: false, logToConsole: true, logToDatabase: false); jobLogger.LogMessage("Test", JobLogger.MessageType.WARNING); Console.ReadKey(); }
protected async Task Run(Job job, IServiceScope scope) { var jobService = scope.ServiceProvider.GetRequiredService <IJobService>(); var procedureService = scope.ServiceProvider.GetRequiredService <IProcedureService>(); var contextFactory = scope.ServiceProvider.GetRequiredService <IContextFactory>(); var log = new JobLogger(_logger, job); var cts = new CancellationTokenSource(); var context = contextFactory.Create(job, log, cts.Token, p => job.Progress = p); jobService.RegisterCanceller(job.Id, () => cts.Cancel(true)); await Task.Factory.StartNew(() => { job.StartAt = DateTime.UtcNow; job.Status = JobStatus.Running; try { var procedure = procedureService.Resolve(job.Name); procedure.ExecuteAsync(context).Wait(context.CancellationToken); } catch (Exception ex) { var baseEx = ex.GetBaseException(); if (baseEx.GetType() == typeof(OperationCanceledException)) { log.LogInformation("<< The job has been canceled. >>"); ExceptionDispatchInfo.Capture(baseEx).Throw(); } else { log.LogError(ex, ex.Message); context.Errors.Add(new Error(ERR_EXCEPTION_THROWN)); } } }, context.CancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default) .ContinueWith(t => { foreach (var error in context.Errors) { log.LogError(error.ToString()); } job.FinishAt = DateTime.UtcNow; if (t.IsCanceled) { job.Status = JobStatus.Canceled; } else { job.Progress = 100; job.Status = context.Errors.Count == 0 ? JobStatus.Success : JobStatus.Faild; } jobService.SaveAsync(job).Wait(context.CancellationToken); }); }
public void ReciboMensajeYquieroErrorPorArchivo() { // JobLogger( logToFile, logToConsole, logToDatabase, logMessage, logWarning, logError) JobLogger instruccion = new JobLogger(true, false, false, false, true, false); //Devuelve True porque yo TENGO un mensaje pero quiero solo guardar por archivo los ERRORES. //Entonces no se llega a ejecutar nunca el Save File. ( Lo evalua y no lo hace, e imprime true) Assert.AreEqual(JobLogger.LogMessage("Mensaje ! soy un mensaje ", true, false, false), true); }
public void LogToDataBaseTest_MessageConfig() { JobLogger.Initialize(false, false, true, EnumLogLevel.Message); JobLogger.LogMessage("Mensaje", EnumLogLevel.Message); // Should log JobLogger.LogMessage("Warning", EnumLogLevel.Warning); // Should log JobLogger.LogMessage("Error", EnumLogLevel.Error); // Should log }
public void InitializeIntelliTest( bool logToFile, bool logToConsole, bool logToDatabase, EnumLogLevel maxlogLevel ) { JobLogger.Initialize(logToFile, logToConsole, logToDatabase, maxlogLevel); // TODO: add assertions to method JobLoggerIntelliTest.InitializeIntelliTest(Boolean, Boolean, Boolean, EnumLogLevel) }
public void LogToFileTest_OffConfig() { JobLogger.Initialize(true, false, false, EnumLogLevel.Error); JobLogger.LogMessage("Mensaje", EnumLogLevel.Message); // Shouldn't log JobLogger.LogMessage("Warning", EnumLogLevel.Warning); // Shouldn't log JobLogger.LogMessage("Error", EnumLogLevel.Error); // Shouldn't log }
public void JobLoggerCannotLogIfHasNotLoggers() { JobLogger jl = JobLogger.Instance; jl.Reset(); jl.AcceptMessages <ErrorMessage>(); jl.LogMessage(new ErrorMessage("Cannot log this message.")); }
public void JobLoggerCannotAcceptMessageTypesFromEmptyCollection() { JobLogger jl = JobLogger.Instance; List <Type> acceptedMessages = new List <Type> { }; jl.SetAcceptedMessages(acceptedMessages); }
public void LogMessageNullTest() { //arrange JobLogger log = new JobLogger(1, null, helper.Object); //act log.LogMessage(); //assert }
public void LogMessageEmptyTest() { //arrange JobLogger log = new JobLogger(1, String.Empty, helper.Object); //act log.LogMessage(); //assert }
protected void CmdGenerar_Click(object sender, EventArgs e) { JobLogger log = new JobLogger(); log.AddLogMessage(); log.Message = "This is the log message"; log.LogWarning = true; log.LogMessage = false; log.LogError = false; }
public void JobLoggerCannotSetLoggersFromEmptyCollection() { JobLogger jl = JobLogger.Instance; List <ILogger> loggers = new List <ILogger> { }; jl.SetLoggers(loggers); }
public static Object ReturnObjType(string dllPath, string DllOrUrl, JobLogger _jobLogger) { Assembly assembly = Assembly.LoadFrom(dllPath); Type type = assembly.GetType(DllOrUrl.Split(',')[1]); object[] parameters = new object[1]; parameters[0] = _jobLogger; object obj = Activator.CreateInstance(type, parameters); return(obj); }
public void ShouldReturnExceptionWhenInvalidConfiguration() { //Arrange var logToFile = false; var logToConsole = false; var logToDatabase = false; var jobLogger = new JobLogger(logToFile, logToConsole, logToDatabase); //Act jobLogger.LogMessage(Constants.TestingMessageLog, LogType.Message); }
public void ConsoleErrorLogIsRed() { JobLogger.LogToConsole(); JobLogger.EnableErrorLog(); var message = "Log error"; JobLogger.LogMessage(message, LogType.Error); Assert.AreEqual(Console.ForegroundColor, ConsoleColor.Red); }
public void ConsoleWarningLogIsYellow() { JobLogger.LogToConsole(); JobLogger.EnableWarningLog(); var message = "Log warning"; JobLogger.LogMessage(message, LogType.Warning); Assert.AreEqual(Console.ForegroundColor, ConsoleColor.Yellow); }
public void ConsoleMessageLogIsWhite() { JobLogger.LogToConsole(); JobLogger.EnableMessageLog(); var message = "Log message"; JobLogger.LogMessage(message, LogType.Message); Assert.AreEqual(Console.ForegroundColor, ConsoleColor.White); }
public void ShouldReturnExceptionWhenEmptyMessage() { //Arrange var logToFile = false; var logToConsole = true; var logToDatabase = false; var jobLogger = new JobLogger(logToFile, logToConsole, logToDatabase); //Act jobLogger.LogMessage(string.Empty, LogType.Message); }
public void LogWarningToFile() { var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var file = System.IO.Path.Combine(documents, "LogFile" + DateTime.Now.ToString("yyyyMMdd") + ".txt"); string message = " First warning message "; JobLogger.LogAMessage(true, false, false, true, true, true, message, false, true, false); //Verify that the file has this new message Assert.True(System.IO.File.ReadAllText(file).Contains(message)); }
public StatusResponse Save(JobLogger objJobLogger) { var savetxt = _IJobLoggerAplicacion.SaveIntoTxt(objJobLogger); if (!savetxt.Success) return new StatusResponse { Success = savetxt.Success, Messages = savetxt.Messages }; var savebd = _IJobLoggerAplicacion.SaveIntoBD(objJobLogger); if (!savebd.Success) return new StatusResponse { Success = savebd.Success, Messages = savebd.Messages }; ColorEnConsola(objJobLogger.Tipo_Mensaje); return new StatusResponse { Success = true, Message = objJobLogger.Mensaje }; }
public void SaveIntoTxt() { var container = Bootstrapper.LoadContainer(); var objJobLogger = new JobLogger { Mensaje = "TestSaveIntoTxt", Tipo_Mensaje = "1" }; using (var scope = container.BeginLifetimeScope()) { var sresolve = scope.Resolve<IJobLoggerAplicacion>(); var obj = new JobLoggerController(sresolve); var statusResponse = obj.SaveIntoTxt(objJobLogger); Assert.AreEqual(true, statusResponse.Success); } }
public StatusResponse SaveIntoTxt(JobLogger objJobLogger) { return _jobLoggerAplicacionProceso.EjecutaSaveIntoTxt(objJobLogger); }
public StatusResponse SaveIntoTxt(JobLogger objJobLogger) { return _IJobLoggerAplicacion.SaveIntoTxt(objJobLogger); }