当前位置: 首页>>代码示例>>C#>>正文


C# Diagnostics.StackFrame类代码示例

本文整理汇总了C#中System.Diagnostics.StackFrame的典型用法代码示例。如果您正苦于以下问题:C# StackFrame类的具体用法?C# StackFrame怎么用?C# StackFrame使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StackFrame类属于System.Diagnostics命名空间,在下文中一共展示了StackFrame类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PromoteException

        //Can only be called inside a service
        public static void PromoteException(Exception error,MessageVersion version,ref Message fault)
        {
            StackFrame frame = new StackFrame(1);

             Type serviceType = frame.GetMethod().ReflectedType;
             PromoteException(serviceType,error,version,ref fault);
        }
开发者ID:JMnITup,项目名称:SMEX,代码行数:8,代码来源:ErrorHandlerHelper.cs

示例2: OnAuthentication

 public void OnAuthentication(AuthenticationContext filterContext)
 {
     System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame();
     System.Reflection.MethodBase methodBase = stackFrame.GetMethod();
     log.Debug("Start: " + methodBase.Name);
     try
     {
         if (UserLogin.ValidateUserRequest())
         {
             filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "Home" }, { "action", "Login" }, { "area", "" } });
         }
         else
         {
             string context = filterContext.Controller.ControllerContext.HttpContext.Request.Path;
             int UserID = Convert.ToInt32(filterContext.HttpContext.Session["UserID"]);
             string Role = MenuBinding.CheckURlAndGetUserRole(context, UserID);
             if (Role == null)
             {
                 filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "Home" }, { "action", "Index" }, { "area", "" } });
             }
             filterContext.Controller.ViewBag.Role = Role;
         }
     }
     catch (Exception ex)
     {
         log.Error("Error: " + ex);
     }
     log.Debug("End: " + methodBase.Name);
 }
开发者ID:reddyjannavarapu,项目名称:css3,代码行数:29,代码来源:CheckUrlAccessCustomFilter.cs

示例3: GetCurrentClassLogger

        /// <summary>
        /// Gets a <see cref="ILog"/> instance named after the caller's declaring or reflected type.
        /// </summary>
        public static ILog GetCurrentClassLogger()
        {
            var caller = new StackFrame(1, false).GetMethod();
            var name = (caller.DeclaringType ?? caller.ReflectedType ?? typeof(UnknownLogger)).FullName;

            return Instance.CreateLogger(name);
        }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:10,代码来源:LogManager.cs

示例4: Include

        public override bool Include(StackFrame frame)
        {
            var method = frame.GetMethod();
            if (IsHiddenMember(method))
            {
                return false;
            }

            var type = method.DeclaringType;

            // TODO (https://github.com/dotnet/roslyn/issues/5250): look for other types indicating that we're in Roslyn code
            if (type == typeof(CommandLineRunner))
            {
                return false;
            }

            // Type is null for DynamicMethods and global methods.
            // TODO (tomat): we don't want to include awaiter helpers, shouldn't they be marked by DebuggerHidden in FX?
            if (type == null || IsTaskAwaiter(type) || IsTaskAwaiter(type.DeclaringType))
            {
                return false;
            }

            return true;
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:25,代码来源:CommonMemberFilter.cs

示例5: GetClassFullName

        // Copied from NLog
        static string GetClassFullName()
        {
            string className;
            Type declaringType;
            int framesToSkip = 2;

            do {
#if SILVERLIGHT
                StackFrame frame = new StackTrace().GetFrame(framesToSkip);
#else
                StackFrame frame = new StackFrame(framesToSkip, false);
#endif
                MethodBase method = frame.GetMethod();
                declaringType = method.DeclaringType;
                if (declaringType == null) {
                    className = method.Name;
                    break;
                }

                framesToSkip++;
                className = declaringType.FullName;
            } while (declaringType.Module.Name.Equals("mscorlib.dll", StringComparison.OrdinalIgnoreCase));

            return className;
        }
开发者ID:Emill,项目名称:Npgsql,代码行数:26,代码来源:NpgsqlLogManager.cs

示例6: Log

        private static void Log(LogLevel logLevel, string msg)
        {
            if (logLevel < LogLevel) return;

            StackFrame frame = new StackFrame(2, true);
            var method = frame.GetMethod();
            var lineNumber = frame.GetFileLineNumber();

            var color = Console.ForegroundColor;
            switch (logLevel)
            {
                case LogLevel.None:
                    break;
                case LogLevel.Debug:
                    Console.ForegroundColor = ConsoleColor.DarkGray;
                    break;
                case LogLevel.Info:
                    Console.ForegroundColor = ConsoleColor.Gray;
                    break;
                case LogLevel.Warning:
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    break;
                case LogLevel.Error:
                    Console.ForegroundColor = ConsoleColor.Red;
                    break;
            }

            Console.WriteLine("{0}.{1}:{2} - {3}", method.DeclaringType.FullName, method.Name, lineNumber, msg);
            Console.ForegroundColor = color;
        }
开发者ID:eriser,项目名称:alphaSynth,代码行数:30,代码来源:Logger.cs

示例7: Enrich

        public void Enrich(LogEvent e, out string propertyName, out object propertyValue)
        {
            var frame = new StackFrame(4);   //warning! this can change after refactoring

             propertyName = "method";

             MethodBase method = frame.GetMethod();
             var sb = new StringBuilder();

             sb.Append(method.DeclaringType.FullName);
             sb.Append(".");
             sb.Append(method.Name);
             sb.Append("(");
             bool isFirst = true;
             foreach(ParameterInfo p in method.GetParameters())
             {
            if (!isFirst)
            {
               sb.Append(", ");
            }
            else
            {
               isFirst = false;
            }
            sb.Append(p.ParameterType.Name);
            sb.Append(" ");
            sb.Append(p.Name);
             }
             sb.Append(")");

             propertyValue = sb.ToString();
        }
开发者ID:aloneguid,项目名称:logmagic,代码行数:32,代码来源:MethodNameEnricher.cs

示例8: GetClassLogger

        public static ScopeLogger GetClassLogger(ILogTape baseLogger = null, int framesToSkip = 1)
        {
            // extracted from: https://github.com/NLog
            string loggerName;
            Type declaringType;

            do
            {
                StackFrame frame = new StackFrame(framesToSkip, false);

                var method = frame.GetMethod();
                declaringType = method.DeclaringType;
                if (declaringType == null)
                {
                    loggerName = method.Name;
                    break;
                }

                framesToSkip++;
                loggerName = declaringType.FullName;
            } while (declaringType.Module.Name.Equals("mscorlib.dll", StringComparison.OrdinalIgnoreCase));

            if (baseLogger == null)
                baseLogger = commonLogTape;

            return new ScopeLogger(loggerName, baseLogger);
        }
开发者ID:alejandraa,项目名称:TaskMQ,代码行数:27,代码来源:ScopeLogger.cs

示例9: HandleException

        public static void HandleException(Exception ex, string msg)
        {
            try
            {
                if (_exceptionUseReflection)
                {
                    var frame = new StackFrame(1);
                    frame.GetMethod();
                }
                if (ex.InnerException != null)
                {
                }
                if (!string.IsNullOrEmpty(msg))
                {
                    msg = "**************" + msg + "**************" + Environment.NewLine;
                }
                else
                {
                    msg = Environment.NewLine;
                }
                var message = (_exceptionRecurseError) ? msg + RecurseErrorStack(ex) : msg;

                if (message.Length > 0)
                {
                    Ea.GetEvent<DisplayExceptionMessage>().Publish(message);
                    Ea.GetEvent<HideBusyIndicator>().Publish(string.Empty);
                }
            }
            catch (Exception iex)
            {
                throw (new Exception("Exception in HandleException(Exception ex, string msg): " + iex.Message));
            }
        }
开发者ID:jwh5293,项目名称:Composer,代码行数:33,代码来源:Exceptions.cs

示例10: GetWebRootFileSystemDirectory

 public static string GetWebRootFileSystemDirectory(string debugPath = null)
 {
     string fileSystemWebRoot = null;
     try
     {
         if (!string.IsNullOrEmpty(debugPath))
         {
             var sf = new StackFrame(0, true);
             var fileName = sf.GetFileName();
             var sourceWebRootDirectory = string.IsNullOrEmpty(fileName)
                                              ? ""
                                              : Path.GetFullPath(Path.Combine(fileName, @"..\..\..", debugPath));
             fileSystemWebRoot = Directory.Exists(sourceWebRootDirectory)
                                     ? sourceWebRootDirectory
                                     : AppDomain.CurrentDomain.BaseDirectory;
         }
         else
         {
             fileSystemWebRoot = AppDomain.CurrentDomain.BaseDirectory;
         }
     }
     catch (Exception)
     {
         fileSystemWebRoot = AppDomain.CurrentDomain.BaseDirectory;
     }
     return fileSystemWebRoot;
 }
开发者ID:robashton,项目名称:EventStore,代码行数:27,代码来源:MiniWeb.cs

示例11: GetCurrentClassLogger

		/// <summary>
		/// 获取日志记录器(为当前类找出匹配的日志记录器)
		/// </summary>
		public ILogger GetCurrentClassLogger()
		{
			var frame = new StackFrame(2);  //调用日志记录器的类所在的堆栈帧
			Type classType = frame.GetMethod().ReflectedType;

			// 查找配置中所有匹配的日志记录器
			IList<ILogger> loggers = FindLoggers(classType);
			if (loggers.Count == 0)
			{
				return LogManager.NullLogger;
			}
			if (loggers.Count == 1)
				return loggers[0];

			MultiLogger logger = new MultiLogger(loggers);
			LogLevel minLevel = LogLevel.Fatal;
			foreach (var logger1 in loggers)
			{
				if (logger1.MinLevel < minLevel)
					minLevel = logger1.MinLevel;
			}

			logger.LoadConfig(new LoggerConfig{MinLevel = minLevel, Name = "MultiLogger"});
			return logger;
		}
开发者ID:Leafney,项目名称:Kalman.Studio,代码行数:28,代码来源:LogProvider.cs

示例12: LogData

 internal LogData (LogLevel level, StackFrame caller, string message)
 {
   _level = level;
   _caller = caller;
   _message = message ?? String.Empty;
   _date = DateTime.Now;
 }
开发者ID:JChan106,项目名称:HACKPOLY16,代码行数:7,代码来源:LogData.cs

示例13: Log

 public static void Log(string message)
 {
     var trace = new StackFrame(1);
     var methodBase = trace.GetMethod();
     var type = methodBase.DeclaringType;
     LogManager.GetLogger(type).Info(message);
 }
开发者ID:ananse23,项目名称:EsriWPF,代码行数:7,代码来源:Logger.cs

示例14: GetCallingType

        public static Type GetCallingType()
        {
            if (EnvironmentHelper.IsProcessHostedByTool)
            {
                return typeof(object);
            }


//#if NETFX_CORE
//            var type = typeof(object);
//#else
//            var stackTrace = StackTraceHelper.GetStackTrace();
//            var stackFrame = stackTrace.GetFrame(2);
//            var type = stackFrame.GetMethod().DeclaringType;
//#endif

#if NET
            var frame = new StackFrame(2, false);
            var type = frame.GetMethod().DeclaringType;
#elif NETFX_CORE
            var type = typeof(object);
#else
            var frame = new StackTrace().GetFrame(2);
            var type = frame.GetMethod().DeclaringType;
#endif

            return type;
        }
开发者ID:pars87,项目名称:Catel,代码行数:28,代码来源:StaticHelper.cs

示例15: GetLastLogin

        public string GetLastLogin(string id)
        {
            var s = "";

            try
            {
                var query = string.Format("SELECT * from WP_GAA_Users where Unique_ID like '{0}';", id);

                using (var connection = new MySqlConnection(ConnectionString))
                {
                    connection.Open();
                    using (var cmd = new MySqlCommand(query, connection))
                    {
                        using (var r = cmd.ExecuteReader())
                        {
                            while (r.Read())
                            {
                                var loginOrdinal = r.GetOrdinal("Last_Used");
                                if (r.IsDBNull(loginOrdinal)) s = DateTime.MinValue.ToString();
                                else s = r.GetString("Last_Used");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var sf = new StackFrame();
                var methodBase = sf.GetMethod();
                Database.InsertErrorToDb(methodBase.Name, ex.Message, ex.ToString());
            }

            return s;
        }
开发者ID:gerardcarroll,项目名称:Roadwatch_GAA_Api,代码行数:34,代码来源:GaaLastLoginController.cs


注:本文中的System.Diagnostics.StackFrame类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。