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


C# StackFrame.GetFileLineNumber方法代码示例

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


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

示例1: toString

        // private static readonly Log log = Log.getLog(typeof(FaultSerializer));

        private static String toString(StackFrame frame)
        {
            String answer = "";
            MethodBase method = frame.GetMethod();

            if( null != method ) 
            {
                answer += "[";
                Type declaringType = method.DeclaringType;
                if (null != declaringType) 
                {
                    String moduleName = declaringType.Name;
                    if (null != moduleName)
                    {
                        answer += moduleName;
                    }
                }
                String methodName = method.Name;
                if (null != methodName)
                {
                    answer += " ";
                    answer += methodName;
                }
                answer += "]";
            }


            if( 0 != answer.Length ) {
                answer += " ";
            }

            String fileName = frame.GetFileName();
            if (null == fileName || 0 == fileName.Length)
            {
                fileName = "?";
            }
            else
            {
                int lastSlash = fileName.LastIndexOf('\\');
                if (-1 != lastSlash)
                {
                    fileName = fileName.Substring(lastSlash+1); // +1 to skip over the '\'
                }
            }


            String lineNumber = "?";
            if (0 != frame.GetFileLineNumber())
            {
                lineNumber = String.Format("{0}", frame.GetFileLineNumber());
            }

            answer += String.Format("({0}:{1})", fileName, lineNumber);

            return answer;

        }
开发者ID:rlong,项目名称:dotnet.lib.HttpLibrary,代码行数:59,代码来源:FaultSerializer.cs

示例2: InternalErrorPrivate

        /// <summary>
        /// Raises an internal error. The reason why this is private is so that only
        /// the other InternalError functions can call it. This ensures that the
        /// function can always backtrack exactly 2 stack frames to get to the place
        /// which invoked InternalError.
        /// </summary>
        private static void InternalErrorPrivate(string errorMsg)
        {
            string str = "Internal application error has occurred. Please inform the developer.\n";
            if (errorMsg != null) str += "\nError message: " + errorMsg;
            StackFrame sf = new StackFrame(2, true);
            str += "\nMethod: " + sf.GetMethod();
            if (sf.GetFileLineNumber() != 0)
                // The line number is zero if there is no program database in the
                // application directory (which is the case when a normal user runs it)
                str += "\nFile: " + sf.GetFileName() + "\nLine: " + sf.GetFileLineNumber();

            DlgMessage.Show(str, "Internal error", DlgType.Error, "OK");
        }
开发者ID:RT-Projects,项目名称:RT.Util,代码行数:19,代码来源:InternalError.cs

示例3: GetStackItem

        // сформировать данные о фрейме стека
        private static StackItem GetStackItem(StackFrame sf)
        {
            if( sf == null )
                        return null;
                MethodBase method = sf.GetMethod();
                if( method == null || method.ReflectedType == null )
                        return null;

                // получить информацию о данном фрейме стека
                StackItem item  = new StackItem();
                item.Module     = method.Module.Assembly.FullName;
                item.ClassName  = method.ReflectedType.Name;
                item.MethodName = method.Name;
                item.FileName   = sf.GetFileName();
                item.Line       = sf.GetFileLineNumber();

                // получить параметры данного метода
                StringBuilder parameters = new StringBuilder();
                ParameterInfo[] paramsInfo = method.GetParameters();
                for( Int32 i = 0; i < paramsInfo.Length; i++ )
                {
                        ParameterInfo currParam = paramsInfo[ i ];
                        parameters.Append( currParam.ParameterType.Name );
                        parameters.Append( " " );
                        parameters.Append( currParam.Name );
                        if( i != paramsInfo.Length - 1 )
                                parameters.Append( ", " );
                }

                item.Params = parameters.ToString();

                return item;
        }
开发者ID:ulqiorra,项目名称:Gyroscope,代码行数:34,代码来源:Dbg.cs

示例4: ExceptionFrame

        /// <summary>
        /// Initializes a new instance of the <see cref="ExceptionFrame"/> class.
        /// </summary>
        /// <param name="frame">The <see cref="StackFrame"/>.</param>
        public ExceptionFrame(StackFrame frame)
        {
            if (frame == null)
                return;

            int lineNo = frame.GetFileLineNumber();

            if (lineNo == 0)
            {
                //The pdb files aren't currently available
                lineNo = frame.GetILOffset();
            }

            var method = frame.GetMethod();
            if (method != null)
            {
                Module = (method.DeclaringType != null) ? method.DeclaringType.FullName : null;
                Function = method.Name;
                Source = method.ToString();
            }
            else
            {
                // on some platforms (e.g. on mono), StackFrame.GetMethod() may return null
                // e.g. for this stack frame:
                //   at (wrapper dynamic-method) System.Object:lambda_method (System.Runtime.CompilerServices.Closure,object,object))

                Module = "(unknown)";
                Function = "(unknown)";
                Source = "(unknown)";
            }

            Filename = frame.GetFileName();
            LineNumber = lineNo;
            ColumnNumber = frame.GetFileColumnNumber();
        }
开发者ID:getsentry,项目名称:raven-csharp,代码行数:39,代码来源:ExceptionFrame.cs

示例5: ConeStackFrame

 public ConeStackFrame(StackFrame frame)
 {
     Method = frame.GetMethod();
     File = frame.GetFileName();
     Line = frame.GetFileLineNumber();
     Column = frame.GetFileColumnNumber();
 }
开发者ID:drunkcod,项目名称:Cone,代码行数:7,代码来源:ConeStackFrame.cs

示例6: logError

    /// bulk of code written by: Alex Marcum - 11/20/2012
    public static void logError(Exception ex)
    {
        System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame(1, true);

        //System.IO.FileInfo temp = new System.IO.FileInfo(fileName);
        //fileName = temp.Name;

        //Class Name is the Whole path to the Filename
        string fileName = stackFrame.GetFileName();
        string functionName = stackFrame.GetMethod().Name.ToString();
        int line = stackFrame.GetFileLineNumber();

        try
        {
            using (CCSEntities db = new CCSEntities())
            {
                ErrorLog el = new ErrorLog();

                el.TimeStamp = DateTime.Now;
                el.FileName = fileName;
                el.FunctionName = functionName;
                el.LineNumber = line.ToString();
                el.ErrorText = ex.Message;

                db.ErrorLogs.Add(el);
                db.SaveChanges();
            }
        }
        catch (Exception /*ex*/)
        {
        }
    }
开发者ID:WsuCS3750,项目名称:CCSInventory,代码行数:33,代码来源:LogError.cs

示例7: 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

示例8: ShowVsAssert

        private static void ShowVsAssert(string stackTrace, StackFrame frame, string message, string detailMessage) {
            int[] disable = new int[1];
            try {
                string detailMessage2;
                
                if (detailMessage == null)
                    detailMessage2 = stackTrace; 
                else
                    detailMessage2 = detailMessage + Environment.NewLine + stackTrace;                
                string fileName = (frame == null) ? string.Empty : frame.GetFileName();
                if (fileName == null) {
                    fileName = string.Empty;
                }

                int lineNumber = (frame == null) ? 0 : frame.GetFileLineNumber();
                int returnCode = VsAssert(detailMessage2, message, fileName, lineNumber, disable);
                if (returnCode != 0) {
                    if (!System.Diagnostics.Debugger.IsAttached) {
                        System.Diagnostics.Debugger.Launch();
                    }
                    System.Diagnostics.Debugger.Break();
                }
                if (disable[0] != 0)
                    ignoredAsserts[MakeAssertKey(fileName, lineNumber)] = null;
            }
            catch (Exception) {
                vsassertPresent = false;
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:29,代码来源:assertwrapper.cs

示例9: Format

 private static LogInfo Format(string msg, Exception ex = null)
 {
     var f = new StackFrame(6, true);
     var method = f.GetMethod();
     var fileInfo = string.Format("{0}[{1}]", f.GetFileName(), f.GetFileLineNumber());
     if (ex != null)
     {
         method = ex.TargetSite;
     }
     var result = new LogInfo
     {
         Method = string.Format("{0} {1}",
             method.DeclaringType,
             method.Name),
         Message = msg,
         File = string.Empty,
         Detail = string.Empty
     };
     result.File = fileInfo;
     if (ex != null)
     {
         result.Detail = ex.Format();
     }
     return result;
 }
开发者ID:shoy160,项目名称:Shoy.Common,代码行数:25,代码来源:Log4NetLog.cs

示例10: StackFrameItem

        /// <summary>
        /// returns a stack frame item from a stack frame. This 
        /// </summary>
        /// <param name="frame"></param>
        /// <returns></returns>
        public StackFrameItem(StackFrame frame)
        {
            // set default values
            m_lineNumber = NA;
            m_fileName = NA;
            m_method = new MethodItem();
            m_className = NA;

			try
			{
				// get frame values
				m_lineNumber = frame.GetFileLineNumber().ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
				m_fileName = frame.GetFileName();
				// get method values
				MethodBase method = frame.GetMethod();
				if (method != null)
				{
					if(method.DeclaringType != null)
						m_className = method.DeclaringType.FullName;
					m_method = new MethodItem(method);
				}
			}
			catch (Exception ex)
			{
				LogLog.Error(declaringType, "An exception ocurred while retreiving stack frame information.", ex);
			}

            // set full info
            m_fullInfo = m_className + '.' + m_method.Name + '(' + m_fileName + ':' + m_lineNumber + ')';
        }
开发者ID:Jsiegelion,项目名称:ExaminationOnline,代码行数:35,代码来源:StackFrameItem.cs

示例11: Log

 static void Log(object message)
 {
     StackFrame frame = new StackFrame(1, true);
     var method = frame.GetMethod();
     var fileName = frame.GetFileName();
     var lineNumber = frame.GetFileLineNumber();
     Console.WriteLine("{0}({1}):{2} - {3}", fileName, lineNumber, method.Name, message);
 }
开发者ID:tamilkpr,项目名称:SampleProject1,代码行数:8,代码来源:Program.cs

示例12: Default

		public void Default ()
		{
			StackFrame sf = new StackFrame ();
			Assert.AreEqual (0, sf.GetFileLineNumber (), "GetFileLineNumber");
			Assert.AreEqual (0, sf.GetFileColumnNumber (), "GetFileColumnNumber");
			Assert.IsTrue (sf.GetILOffset () >= 0, "GetILOffset");
			Assert.IsTrue (sf.GetNativeOffset () >= 0, "GetNativeOffset");
			Assert.AreEqual ("Default", sf.GetMethod ().Name, "GetMethod");
		}
开发者ID:dfr0,项目名称:moon,代码行数:9,代码来源:StackFrameTest.cs

示例13: Write

 public override void Write(string message)
 {
     StackFrame sf = new StackFrame (5, true);
     string fileName = sf.GetFileName();
     int lineNumber = sf.GetFileLineNumber();
     string methodName = sf.GetMethod ().Name;
     string prefix = "["+ fileName + ":" + lineNumber +" (" + methodName + ")]";
     base.Write ( prefix + message);
 }
开发者ID:BackupTheBerlios,项目名称:simetron,代码行数:9,代码来源:Diagnostics.cs

示例14: FileName_LineNumber_ColumnNumber

		public void FileName_LineNumber_ColumnNumber ()
		{
			StackFrame sf = new StackFrame (String.Empty, Int32.MinValue, Int32.MaxValue);
			Assert.AreEqual (Int32.MinValue, sf.GetFileLineNumber (), "GetFileLineNumber");
			Assert.AreEqual (Int32.MaxValue, sf.GetFileColumnNumber (), "GetFileColumnNumber");
			Assert.IsTrue (sf.GetILOffset () >= 0, "GetILOffset");
			Assert.IsTrue (sf.GetNativeOffset () > 0, "GetNativeOffset");
			Assert.AreEqual ("FileName_LineNumber_ColumnNumber", sf.GetMethod ().Name, "GetMethod");
		}
开发者ID:dfr0,项目名称:moon,代码行数:9,代码来源:StackFrameTest.cs

示例15: GetExtraInfo

		static string GetExtraInfo (StackFrame sf = null)
		{
			string threadid = String.Format ("thread_id: {0}", Thread.CurrentThread.ManagedThreadId.ToString ("x"));
			string domainid = String.Format ("appdomain_id: {0}", AppDomain.CurrentDomain.Id.ToString ("x"));			
			string filepath = sf == null ? null : sf.GetFileName ();
			int lineNumber = sf == null ? -1 : sf.GetFileLineNumber ();
			string format = String.IsNullOrEmpty (filepath) ? " [{0}, {1}]" : " [{0}, {1}, in {2}:{3}]";
			return String.Format (format, domainid, threadid, filepath, lineNumber);
		}
开发者ID:louislatreille,项目名称:xsp,代码行数:9,代码来源:WebTrace.cs


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