示例#1
0
 protected override void InterceptIntern(IInvocation invocation)
 {
     try
     {
         int     startTicks     = 0;
         ILogger loggerOfMethod = LoggerFactory.GetLogger(invocation.Method.DeclaringType, Properties);
         bool    debugEnabled   = Log.DebugEnabled && loggerOfMethod.DebugEnabled;
         if (debugEnabled)
         {
             if (IsClientLogger)
             {
                 loggerOfMethod.Debug("Start:     " + LogTypesUtil.PrintMethod(invocation.Method, PrintShortStringNames));
             }
             else
             {
                 loggerOfMethod.Debug("Start(S):  " + LogTypesUtil.PrintMethod(invocation.Method, PrintShortStringNames));
             }
             startTicks = Environment.TickCount;
         }
         InvokeTarget(invocation);
         if (debugEnabled)
         {
             int    endTicks     = Environment.TickCount;
             Object returnValue  = invocation.ReturnValue;
             int    resultCount  = returnValue is ICollection ? ((ICollection)returnValue).Count : returnValue != null ? 1 : -1;
             String resultString = resultCount >= 0 ? "" + resultCount : "no";
             String itemsString  = typeof(void).Equals(invocation.Method.ReturnType) ? "" : " with " + resultString + (resultCount != 1 ? " items" : " item");
             if (IsClientLogger)
             {
                 loggerOfMethod.Debug("Finish:    " + LogTypesUtil.PrintMethod(invocation.Method, PrintShortStringNames) + itemsString + " (" + (endTicks - startTicks) + " ms)");
             }
             else
             {
                 loggerOfMethod.Debug("Finish(S): " + LogTypesUtil.PrintMethod(invocation.Method, PrintShortStringNames) + itemsString + " (" + (endTicks - startTicks) + " ms)");
             }
         }
     }
     catch (TargetInvocationException e)
     {
         Exception ex = e.InnerException;
         if (ExceptionHandler != null)
         {
             ex = ExceptionHandler.HandleException(invocation.Method, ex);
         }
         if (Log.ErrorEnabled)
         {
             Log.Error(ex);
         }
         throw new RethrownException(ex);
     }
     catch (Exception e)
     {
         if (Log.ErrorEnabled)
         {
             Log.Error(e);
         }
         throw;
     }
 }
示例#2
0
        public virtual void AfterStarted(IServiceContext beanContext)
        {
            if (Log.InfoEnabled)
            {
                IEnumerable <Type> types = FullServiceModelProvider.RegisterKnownTypes(null);

#if !SILVERLIGHT
                SortedList <String, String> sortedTypes = new SortedList <String, String>();

                SortedList <String, String> sortedListTypes = new SortedList <String, String>();

                foreach (Type type in types)
                {
                    String name = LogTypesUtil.PrintType(type, true);
                    if (type.IsGenericType)
                    {
                        sortedListTypes.Add(name, name);
                    }
                    else
                    {
                        sortedTypes.Add(name, name);
                    }
                }
                Log.Info(sortedTypes.Count + " data types");
                Log.Info(sortedListTypes.Count + " collection types");
                DictionaryExtension.Loop(sortedTypes, delegate(String key, String value)
                {
                    Log.Info("Type: " + value);
                });
                DictionaryExtension.Loop(sortedListTypes, delegate(String key, String value)
                {
                    Log.Info("Type: " + value);
                });
#else
                List <String> sortedTypes = new List <String>();

                List <String> sortedListTypes = new List <String>();

                foreach (Type type in types)
                {
                    String        name = LogTypesUtil.PrintType(type, true);
                    List <String> list;
                    if (type.IsGenericType)
                    {
                        list = sortedListTypes;
                    }
                    else
                    {
                        list = sortedTypes;
                    }
                    bool inserted = false;
                    for (int a = list.Count; a-- > 0;)
                    {
                        String item = list[a];
                        if (item.CompareTo(name) < 0)
                        {
                            list.Insert(a + 1, name);
                            inserted = true;
                            break;
                        }
                    }
                    if (!inserted)
                    {
                        list.Insert(0, name);
                    }
                }
                Log.Info(sortedTypes.Count + " data types");
                Log.Info(sortedListTypes.Count + " collection types");
                foreach (String value in sortedTypes)
                {
                    Log.Info("Type: " + value);
                }
                foreach (String value in sortedListTypes)
                {
                    Log.Info("Type: " + value);
                }
#endif
            }
        }