/// <summary> /// Logs the transaction details to log file /// </summary> public void Log() { try { string severityLevel = "NONE"; Type type = typeof(LogLevel); if (severityLevelId >= (byte)LogLevel.DEBUG && severityLevelId <= (byte)LogLevel.FATAL) { severityLevel = Enum.GetNames(type)[severityLevelId]; } LogLevel currentSeverityLevel = AvaLoggerConfiguration.ConvertToLogLevel(severityLevel); if ((AvaLoggerConfiguration.CurrentLogLevel <= currentSeverityLevel) && (currentSeverityLevel != LogLevel.NONE)) { string data = string.Format("{0},{1},{2},{3},{4},{5},\"{6}\",{7},{8},\"{9}\"", transactionId, clientTimestamp, accountId, machineName, serviceName, operation, referenceCode, clientDuration, severityLevelId, errorMessage); Utilities.FileWriter(AvaLoggerConfiguration.TransactionsFileName, data); } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("An error occured while logging transaction details. " + ex.Message); } }
private AvaLogger() { logLevel = AvaLoggerConfiguration.CurrentLogLevel; if (!AvaLoggerConfiguration.LoadConfiguration()) { Trace.WriteLine("Configuration error"); } }
/// <summary> /// Copy To LogFile /// </summary> /// <param name="fromStream"></param> /// <param name="message"></param> /// <param name="isSoapRequest"></param> public void CopyToLogFile(Stream fromStream, SoapMessage message, bool isSoapRequest) { if (!AvaLoggerConfiguration.LogSoap) { return; } string data = string.Empty; string soapString = string.Empty; LogicalMethodInfo methodInfo = message.MethodInfo; string service = methodInfo.DeclaringType.Name; if (service.StartsWith("Proxy")) { service = service.Substring(5); } if (isSoapRequest) { header = "<SoapOperation service=\"" + service + "\" name=\"" + methodInfo.Name + "\""; soapString = (message is SoapServerMessage) ? "SoapResponse" : "SoapRequest"; } else { soapString = (message is SoapServerMessage) ? "SoapRequest" : "SoapResponse"; } fromStream.Position = 0; data += "<" + soapString + " time=\"" + DateUtil.GetDateTimeStamp() + "\">"; data += Utilities.ConvertStreamToString(fromStream); data = data.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", ""); data = Regex.Replace(data, "PasswordText\">.*</Password>", "PasswordText\"></Password>"); data += "</" + soapString + ">"; if (!isSoapRequest) { data += "</SoapOperation>"; } try { if (!isSoapRequest) { string searchElement = "<ResultCode>"; int startIndex = data.IndexOf(searchElement); LogLevel currentSeverityLevel = LogLevel.NONE; if (startIndex != -1) { // To retrieve ResultCode from SoapTrace int endIndex = data.IndexOf("</ResultCode>"); startIndex += searchElement.Length; int len = endIndex - startIndex; string severityLevel = data.Substring(startIndex, len); currentSeverityLevel = AvaLoggerConfiguration.ConvertToLogLevel(severityLevel); // To retrieve TransactionId from SoapTrace searchElement = "<TransactionId>"; startIndex = data.IndexOf(searchElement); endIndex = data.IndexOf("</TransactionId>"); startIndex += searchElement.Length; len = endIndex - startIndex; header += " TransactionId=\"" + data.Substring(startIndex, len) + "\">"; } if ((AvaLoggerConfiguration.CurrentLogLevel <= currentSeverityLevel) && (currentSeverityLevel != LogLevel.NONE)) { Utilities.FileWriter(filename, header + logString + Environment.NewLine + data); } logString = string.Empty; } else { logString = data; } } catch (IOException ex) { _avaLog.Error(string.Format("File open or creation failed: {0}. {1}", filename, ex.Message)); } }