Exemplo n.º 1
0
        public object BeforeCall(string operationName, object[] inputs)
        {
            if (ServiceType == null)
            {
                return(null);
            }

            MethodInfo mi = ServiceType.GetMethod(operationName);

            if (mi == null)
            {
                return(null);
            }

            if (!LogArguments)
            {
                inputs = null;
            }

            SetLoggingContext(inputs, mi);

            if (LogBeforeCall)
            {
                LoggingArgument arg = CreateArgumentForInvokeLog(mi, inputs);

                LoggingStrategy.Log(arg);
            }

            return(null);
        }
Exemplo n.º 2
0
        public bool Log(LoggingArgument arg)
        {
            if (arg == null)
            {
                return(false);
            }

            try
            {
                string logFilePath = FilePath ?? "C:\\Example.txt";

                using (FileStream fs = File.Open(logFilePath, FileMode.Append, FileAccess.Write))
                {
                    using (TextWriter tw = new StreamWriter(fs))
                    {
                        tw.Write(arg.ToString());
                    }
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        private LoggingArgument CreateArgumentForResultLog(MethodInfo mi, object[] outputs, object returnValue)
        {
            if (mi == null)
            {
                return(null);
            }

            LoggingArgument res =
                new LoggingArgument
            {
                LogType       = LoggingType.Result,
                OperationName = mi.Name
            };

            if (outputs != null && outputs.Length > 0)
            {
                res.OutputsData = new LoggingOutputsData
                {
                    OutputParameters =
                        mi.GetParameters().Where(p => p.IsOut || p.ParameterType.IsByRef).ToArray(),
                    OutputValues = outputs
                };
            }

            if (mi.ReturnType != typeof(void))
            {
                res.ReturnValueData = new LoggingReturnValueData
                {
                    Value = returnValue
                };
            }

            return(res);
        }
Exemplo n.º 4
0
        private LoggingArgument CreateArgumentForInvokeLog(MethodInfo mi, object[] inputs)
        {
            if (mi == null)
            {
                return(null);
            }

            OperationContext              oOperationContext              = OperationContext.Current;
            MessageProperties             oMessageProperties             = oOperationContext.IncomingMessageProperties;
            RemoteEndpointMessageProperty oRemoteEndpointMessageProperty = (RemoteEndpointMessageProperty)oMessageProperties[RemoteEndpointMessageProperty.Name];

            string szAddress = oRemoteEndpointMessageProperty.Address;
            int    nPort     = oRemoteEndpointMessageProperty.Port;

            LoggingArgument res =
                new LoggingArgument
            {
                LogType       = LoggingType.Invoke,
                OperationName = mi.Name,
                CallerIp      = szAddress,
                CallerPort    = nPort
            };

            if (inputs != null && inputs.Length > 0)
            {
                res.InputsData = new LoggingInputsData
                {
                    InputParameters = mi.GetParameters().Where(p => !p.IsOut).ToArray(),
                    InputValues     = inputs
                };
            }

            return(res);
        }
        public bool Log(LoggingArgument arg)
        {
            if (arg == null)
            {
                return(false);
            }

            ConsoleColor oldForeground = Console.ForegroundColor;

            switch (arg.LogType)
            {
            case LoggingType.Invoke:
                Console.ForegroundColor = InvokeLogColor;
                break;

            case LoggingType.Result:
                Console.ForegroundColor = ResultLogColor;
                break;

            case LoggingType.Error:
                Console.ForegroundColor = ErrorLogColor;
                break;

            case LoggingType.Warning:
                Console.ForegroundColor = WarningLogColor;
                break;

            case LoggingType.Information:
                Console.ForegroundColor = InformationLogColor;
                break;

            default:
                break;
            }

            Console.WriteLine(arg.ToString());

            Console.ForegroundColor = oldForeground;

            return(true);
        }
Exemplo n.º 6
0
        public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState)
        {
            LoggingContext.ClearCurrentContextDetails();

            if (!Log)
            {
                return;
            }

            if (!LogAfterCall)
            {
                return;
            }

            if (ServiceType == null)
            {
                return;
            }

            if (!LogArguments)
            {
                outputs = null;
            }

            if (!LogReturnVal)
            {
                returnValue = typeof(void);
            }

            MethodInfo mi = ServiceType.GetMethod(operationName);

            if (mi == null)
            {
                return;
            }

            LoggingArgument arg = CreateArgumentForResultLog(mi, outputs, returnValue);

            LoggingStrategy.Log(arg);
        }
Exemplo n.º 7
0
        private LoggingArgument CreateArgumentForCommonLog()
        {
            LoggingArgument arg = new LoggingArgument();

            MethodInfo mi = Details.MethodDetails;

            if (mi != null)
            {
                arg.OperationName = mi.Name;

                if (Details.Inputs != null && Details.Inputs.Length > 0)
                {
                    arg.InputsData = new LoggingInputsData
                    {
                        InputParameters = mi.GetParameters().Where(p => !p.IsOut).ToArray(),
                        InputValues     = Details.Inputs
                    };
                }
            }

            return(arg);
        }
Exemplo n.º 8
0
        public bool Log(Exception ex, string text, LoggingType logType)
        {
            LoggingArgument arg = CreateArgumentForCommonLog();

            arg.LogType = logType;

            if (ex != null)
            {
                arg.ExceptionData = new LoggingExceptionData
                {
                    Exception = ex
                };
            }

            if (text != null)
            {
                arg.InformationData = new LoggingInformationData
                {
                    Text = text
                };
            }

            return(Details.LoggingStrategy.Log(arg));
        }
Exemplo n.º 9
0
 public bool Log(LoggingArgument arg)
 {
     log.Debug(arg.ToString());
     return(true);
 }