/// <summary> /// Write a fatal log to the server /// </summary> /// <param name="className"> /// the class name /// </param> /// <param name="taskId"> /// It is the task id /// </param> /// <param name="message"> /// log message /// </param> public void Fatal(string className, int taskId, string message) { ILog logger = LogManager.GetLogger(className); MessagePact messagePack = this.GetMessagePack(taskId, message, -1); logger.Fatal(messagePack); }
/// <summary> /// Report the status to the server /// </summary> /// <param name="className"> /// the class name /// </param> /// <param name="taskId"> /// It is the task id /// </param> /// <param name="status"> /// the status /// </param> /// <param name="details"> /// the details of the status /// </param> public void ReportStatus(string className, int taskId, int status, string details) { ILog logger = LogManager.GetLogger(className); MessagePact messagePack = this.GetMessagePack(taskId, details, status); logger.Info(messagePack); }
/// <summary> /// Instance a MessagePack /// </summary> /// <param name="taskId"> /// It is the task id /// </param> /// <param name="message"> /// log message /// </param> /// <param name="status"> /// The status, it is available when ReportStatus /// </param> /// <returns> /// It is a class /// </returns> private MessagePact GetMessagePack(int taskId, string message, int status) { var messagePack = new MessagePact(); messagePack.Taskid = taskId; messagePack.MessageDetails = message; messagePack.AStatus = status; if (status == -1) { messagePack.MessageType = MsgType.MtLog; } else { messagePack.MessageType = MsgType.MtStatus; } return(messagePack); }
/// <summary> /// Report the status to the server /// </summary> /// <typeparam name="TP"> /// type of the class /// </typeparam> /// <param name="className"> /// component's name /// </param> /// <param name="taskId"> /// task id /// </param> /// <param name="status"> /// a status /// </param> /// <param name="details"> /// a details /// </param> /// <param name="callFun"> /// a function /// </param> public void ReportStatus <TP>(string className, int taskId, int status, TP details, Func <TP, string> callFun) where TP : class { ILog logger = LogManager.GetLogger(className); string s; if (callFun == null) { s = JsonConvert.SerializeObject(details); } else { s = callFun(details); } MessagePact messagePack = this.GetMessagePack(taskId, s, status); logger.Info(messagePack); }
/// <summary> /// It is a listener /// </summary> /// <param name="sender"> /// a sender /// </param> /// <param name="e"> /// a packed message /// </param> private static void LogListener(object sender, LogEventArgs e) { LogLevel = e.LogEvent.Level; LoggerName = e.LogEvent.LoggerName; TheReturnPact = (MessagePact)e.LogEvent.MessageObject; }