Beispiel #1
0
        /// <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
                });
            }
        }
Beispiel #2
0
        private static void LogMethodCallThread(object oParameters)
        {
            LogMethodParams parameters = (LogMethodParams)oParameters;

            try {
                using (LegionLinqDataContext legion = new LegionLinqDataContext(ConfigurationManager.ConnectionStrings["LegionConnectionString"].ToString())) {
                    legion.xspLogMethodCall(
                        parameters.MethodId,
                        parameters.ExecutionDuration,
                        parameters.CalledAt,
                        parameters.ApplicationId,
                        parameters.HandledByIpAddress,
                        parameters.HostIpAddress,
                        parameters.UserIpAddress,
                        parameters.PermanentLog
                        );
                }
            }
            catch (SqlException) {
                //TODO: Log to flat file
            }
        }