/// <summary> /// An XML representation of the Request /// </summary> /// <returns>an XML string</returns> public string ToXml() { XmlDocument dom = new XmlDocument(); XmlElement root = (XmlElement)dom.AppendChild(dom.CreateElement("request")); root.SetAttribute("id", Id.ToString()); root.AppendChild(dom.CreateElement("servicekey")).InnerText = ServiceKey; root.AppendChild(dom.CreateElement("methodkey")).InnerText = MethodKey; root.AppendChild(dom.CreateElement("formatkey")).InnerText = FormatKey; XmlElement application = (XmlElement)root.AppendChild(dom.CreateElement("application")); application.AppendChild(dom.CreateElement("id")).InnerText = APIKey.Application.Id.ToString(); application.AppendChild(dom.CreateElement("name")).InnerText = APIKey.Application.Name; application.AppendChild(dom.CreateElement("apikey")).InnerText = APIKey.Key; root.AppendChild(dom.CreateElement("isservicetoservice")).InnerText = IsServiceToService.ToString(); root.AppendChild(dom.CreateElement("clientipaddress")).InnerText = Requestor.ClientIPAddress; root.AppendChild(dom.CreateElement("hostipaddress")).InnerText = Requestor.HostIPAddress; root.AppendChild(dom.CreateElement("ishostinternal")).InnerText = Requestor.IsHostInternal.ToString(); XmlDocumentFragment xFragment = dom.CreateDocumentFragment(); xFragment.InnerXml = ParameterSet.ToXml().OuterXml; root.AppendChild(xFragment); return(dom.OuterXml); }
/// <summary> /// Logs the method call to database /// </summary> /// <param name="calledAt">The DateTime the Requeswas made</param> /// <param name="executeStart">The DateTime the Request was passed to the Method</param> /// <param name="executeEnd">The DateTime the Method finished processing and control was passed back to the framework</param> /// <param name="application">The application calling the method</param> /// <param name="serviceKey">The key of the service which was called</param> /// <param name="parameters">The parameters which were passed into the method</param> /// <param name="hostIPAddress">The IP address of the host calling the method</param> /// <param name="userIPAddress">The IP address of the user calling the method</param> /// <param name="permanentLog">Should a record of this call be made in the premenant log</param> internal void LogCall(DateTime calledAt, DateTime executeStart, DateTime executeEnd, Application application, string serviceKey, ParameterSet parameters, string hostIPAddress, string userIPAddress, bool permanentLog) { LogMethodParams call = new LogMethodParams() { MethodId = (_id == -1 ? null : (int?)_id), ExecutionDuration = (executeEnd - executeStart).TotalMilliseconds, CalledAt = calledAt, ApplicationId = application.Id, APIKey = application.APIKey, HandledByIpAddress = ServerDetails.IPv4Addresses.First().ToString(), HostIpAddress = hostIPAddress, UserIpAddress = userIPAddress, PermanentLog = permanentLog, ParameterSet = parameters }; if (Settings.GetBool("CallLogBufferEnabled")) { _bufferedCallLogQueue.Enqueue(call); } else { ParameterizedThreadStart work = new ParameterizedThreadStart(LogMethodCallThread); Thread thread = new Thread(work); thread.Start(call); } if (permanentLog) { string entry = Settings.GetString("LogFormatMethodCall", new Dictionary <string, string>() { { "ApplicationId", application.Id.ToString() }, { "ApplicationName", application.Name }, { "MethodId", _id.ToString() }, { "ServiceKey", serviceKey }, { "MethodKey", _key }, { "Parameters", parameters.ToXml().OuterXml } }); Logging.Module.WriteEvent(new LoggedEvent(EventLevel.Event, string.Format("{0}.{1}", serviceKey, _key), entry) { Async = true, Group = "ServiceCallAudit", ApplicationType = ApplicationType.Application, ApplicationName = application.Name, ClientIp = userIPAddress, HostIp = hostIPAddress }); } }