public static void LogRequest(this ICSCloudLogService logService, CSCloudRequest request, CSCloud.Enums.CSCloudSeverity severity, string message = null, string stackTrace = null) { if (logService == null) return; try { if (request == null) throw new ArgumentNullException("request"); logService.Log(CSCloudLogEntry.FromRequest(request, severity, message, stackTrace)); } catch (Exception ex) { Debug.WriteLine(string.Format("Could not log request to Log Service: {2}\n{0}\n{1}", ex.Message, ex.StackTrace, request.ToString())); } }
public static CSCloudLogEntry FromRequest(CSCloudRequest request, CSCloudSeverity severity, string message, string stackTrace = null) { if (request == null) return null; CSCloudLogEntry log = new CSCloudLogEntry(); log.Date = DateTime.UtcNow; log.Severity = severity; StringBuilder sb = new StringBuilder(); sb.AppendLine(request.ToString()); if (message != null) sb.AppendLine().Append(message); if (stackTrace != null) sb.AppendLine().AppendLine(stackTrace); log.Message = sb.ToString(); return log; }
private CSCloudResponse SendCommand(ICSCloudClient client, CSCloudCommand command) { var request = new CSCloudRequest(); request.ClientName = client.GetName(); request.Command = command; CSCloudResponse response = null; try { LogRequest(request, CSCloudSeverity.INFO, string.Format("Client: {0} has been sent Command: {1}", client.GetName(), request.ToString())); response = client.ExecuteCommand(request); LogResponse(response, CSCloudSeverity.INFO); if (CommandSent != null) CommandSent(this, new CommandSentEventArgs(client, command)); } catch (Exception ex) { LogResponse(response, CSCloudSeverity.ERROR, ex.Message, ex.StackTrace); } return response; }