Beispiel #1
0
        public static void LogMethod(MethodLogEntry logEntry)
        {
            ILogger logger = create(logEntry.LogType);

            logEntry = (MethodLogEntry)refineLogEntry(logEntry);
            MethodLogDelegate dlgt = new MethodLogDelegate(logger.LogMethod);
            IAsyncResult      ar   = dlgt.BeginInvoke(logEntry, null, null);
        }
Beispiel #2
0
 public void LogMethod(MethodLogEntry logEntry)
 {
     using (IUnitOfWork unit = pManager.UnitOfWorkFactory.CreateIsolatedUnitOfWork(false, true, null, null, null, null))
     {
         IRepository <MethodLogEntry> repo = unit.GetRepository <MethodLogEntry>();
         repo.Put(logEntry);
         unit.Commit();
     }
 }
        public sealed override void OnExit(MethodExecutionArgs args)
        {
            if (!AppConfiguration.IsLoggingEnable || !AppConfiguration.IsPerformanceLoggingEnable)
            {
                return;
            }
            if (args.Exception != null) // don't log if there is am exception in the call context. it is likely captured by an exception logger
            {
                return;
            }

            var sw = (Stopwatch)args.MethodExecutionTag;

            sw.Stop();

            MethodLogEntry mLog = new MethodLogEntry();

            mLog.UTCDate   = AppConfiguration.UTCDateTime;
            mLog.CultureId = AppConfiguration.Culture.Name;
            string tempUser = string.Empty;

            mLog.UserId = Constants.AnonymousUser;
            if (AppConfiguration.TryGetCurrentUser(ref tempUser))
            {
                mLog.UserId = tempUser;
            }
            mLog.RequestURL = AppConfiguration.CurrentRequestURL.ToString();

            mLog.AssemblyName    = args.Method.DeclaringType.Assembly.GetName().Name;               //
            mLog.AssemblyVersion = args.Method.DeclaringType.Assembly.GetName().Version.ToString(); //
            mLog.ClassName       = args.Method.DeclaringType.FullName;
            mLog.MethodName      = args.Method.Name.TrimStart("~".ToCharArray());

            mLog.ProcessingTime = sw.ElapsedMilliseconds;
            mLog.Desription     = "NA";

            mLog.LogType = LogType.Performance;
            LoggerFactory.LogMethod(mLog);
#if DEBUG
            Debug.WriteLine(string.Format("Diagnose is called on {0}.{1} at {2}", mLog.ClassName, mLog.MethodName, mLog.UTCDate));
#endif
        }
Beispiel #4
0
        public sealed override void OnInvoke(MethodInterceptionArgs args)

        {
            if (!AppConfiguration.IsLoggingEnable || !AppConfiguration.IsCallLoggingEnable)
            {
                return;
            }
            base.OnInvoke(args);
            /// if invocation of the original method encounters any exception,
            /// the remaining code will not execute, hence no call is recorded.
            /// if needed the method should be tagged with an ExceptionLogAttribute, too.

            MethodLogEntry mLog = new MethodLogEntry();

            mLog.UTCDate   = AppConfiguration.UTCDateTime;
            mLog.CultureId = AppConfiguration.Culture.Name;
            string tempUser = string.Empty;

            mLog.UserId = Constants.AnonymousUser;
            if (AppConfiguration.TryGetCurrentUser(ref tempUser))
            {
                mLog.UserId = tempUser;
            }
            mLog.RequestURL = AppConfiguration.CurrentRequestURL.ToString();
            //mLog = (MethodLogEntry)LoggerFactory.GetEnvironemntLogEntry();

            mLog.AssemblyName    = args.Method.DeclaringType.Assembly.GetName().Name;//
            mLog.AssemblyVersion = args.Method.DeclaringType.Assembly.GetName().Version.ToString();
            mLog.ClassName       = args.Method.DeclaringType.FullName;
            mLog.MethodName      = args.Method.Name.TrimStart("~".ToCharArray()); // PostSharp renames the original method name be adding a leading tilde "~"

            mLog.LogType = LogType.Call;
            LoggerFactory.LogMethod(mLog);
#if DEBUG
            Debug.WriteLine(string.Format("Trace is called on {0}.{1} at {2}", mLog.ClassName, mLog.MethodName, mLog.UTCDate));
#endif
        }
        public sealed override void OnException(MethodExecutionArgs args)
        {
            //base.OnException(eventArgs);

            if (!AppConfiguration.IsLoggingEnable || !AppConfiguration.IsExceptionLoggingEnable)
            {
                return;
            }

            MethodLogEntry mLog = new MethodLogEntry();

            mLog.UTCDate   = AppConfiguration.UTCDateTime;
            mLog.CultureId = AppConfiguration.Culture.Name;
            string tempUser = string.Empty;

            mLog.UserId = Constants.AnonymousUser;
            if (AppConfiguration.TryGetCurrentUser(ref tempUser))
            {
                mLog.UserId = tempUser;
            }
            mLog.RequestURL = AppConfiguration.CurrentRequestURL.ToString();

            mLog.AssemblyName    = args.Method.DeclaringType.Assembly.GetName().Name;//
            mLog.AssemblyVersion = args.Method.DeclaringType.Assembly.GetName().Version.ToString();
            mLog.ClassName       = args.Method.DeclaringType.FullName;
            mLog.MethodName      = args.Method.Name.TrimStart("~".ToCharArray());

            mLog.Desription = args.Exception.Message; // recursive message traversal would be an improvement!
            mLog.ExtraInfo  = string.Format("ExceptionClass={0}", args.Exception.GetType().Name);

            mLog.LogType = LogType.Exception;
            LoggerFactory.LogMethod(mLog);
#if DEBUG
            Debug.WriteLine(string.Format("Diagnose is called on {0}.{1} at {2}", mLog.ClassName, mLog.MethodName, mLog.UTCDate));
#endif
        }
Beispiel #6
0
        public sealed override void OnExit(MethodExecutionArgs args)
        {
            var sw = (Stopwatch)args.MethodExecutionTag;

            sw.Stop();

            if (!AppConfiguration.IsLoggingEnable || !AppConfiguration.IsDiagnosticLoggingEnable)
            {
                return;
            }
            if (args.Exception != null) // don't log if there is am exception in the call context. it is likely captured by an exception logger
            {
                return;
            }

            MethodLogEntry mLog = new MethodLogEntry();

            mLog.UTCDate   = AppConfiguration.UTCDateTime;
            mLog.CultureId = AppConfiguration.Culture.Name;
            string tempUser = string.Empty;

            mLog.UserId = Constants.AnonymousUser;
            if (AppConfiguration.TryGetCurrentUser(ref tempUser))
            {
                mLog.UserId = tempUser;
            }
            mLog.RequestURL      = AppConfiguration.CurrentRequestURL.ToString();
            mLog.AssemblyName    = args.Method.DeclaringType.Assembly.GetName().Name;
            mLog.AssemblyVersion = args.Method.DeclaringType.Assembly.GetName().Version.ToString();
            mLog.ClassName       = args.Method.DeclaringType.FullName;
            mLog.MethodName      = args.Method.Name.TrimStart("~".ToCharArray());

            String[] strArray;
            try
            {
                ParameterInfo[] pms = args.Method.GetParameters();//.ToList().ForEach(p=> p.ToString())
                strArray        = Array.ConvertAll <ParameterInfo, string>(pms, new Converter <ParameterInfo, string>(delegate(ParameterInfo pmi) { return(pmi.ToString()); }));
                mLog.Parameters = string.Join(", ", strArray);
            }
            catch (Exception ex) { }
            try
            {
                object[] argArray = args.Arguments.ToArray();
                strArray = Array.ConvertAll <object, string>(argArray,
                                                             new Converter <object, string>(delegate(object arg)
                {
                    if (arg != null)
                    {
                        return(arg.ToString());
                    }
                    else
                    {
                        return("NULL");
                    }
                }
                                                                                            ));
                mLog.ParameterValues = string.Join(", ", strArray);
            }
            catch (Exception ex) { }
            mLog.ReturnType = args.ReturnValue != null?args.ReturnValue.GetType().FullName : args.Method.GetType().Name;

            try
            {
                if (args.ReturnValue != null)
                {
                    if (args.ReturnValue.ToString().Length <= 255)      // just to limit the size to comply with the DB
                    {
                        mLog.ReturnValue = args.ReturnValue.ToString(); //
                    }
                    else
                    {
                        mLog.ReturnValue = args.ReturnValue.ToString().Substring(0, 252) + "...";
                    }
                }
                else
                {
                    mLog.ReturnValue = string.Empty;
                }
            }
            catch { }
            mLog.ProcessingTime = sw.ElapsedMilliseconds;
            mLog.Desription     = "NA";

            mLog.LogType = LogType.Diagnosis;
            LoggerFactory.LogMethod(mLog);
#if DEBUG
            Debug.WriteLine(string.Format("Diagnose is called on {0}.{1} at {2}", mLog.ClassName, mLog.MethodName, mLog.UTCDate));
#endif
        }
Beispiel #7
0
 public void LogMethod(MethodLogEntry logEntry)
 {
     throw new NotImplementedException();
 }