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


C# StackTrace.GetFileName方法代码示例

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


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

示例1: Log

        public void Log(string type, string message, LogLevel level)
        {
            string msg = message;
            if (!string.IsNullOrWhiteSpace(type)) msg = string.Format("[{0}]{1}", type, message);
            if (level == LogLevel.Debug)
            {
                StackFrame x = new StackTrace(true).GetFrame(1);
                string MethodName = x.GetMethod().Name;
                string Filename = x.GetFileName();
                int Line = x.GetFileLineNumber();

                msg = string.Format("[{0,-3}]{1,-12}:{2,-4} {3}",
                               MethodName,
                               Filename,
                               Line,
                               msg);
            }

            TDebugInfo db = new TDebugInfo()
            {
                Level = level,
                Text = msg,
            };

            if (this.OnLog != null)
            {
                OnLog(this, new LogArgs() { DebugInfo = db });
            }
        }
开发者ID:rajeshwarn,项目名称:rasg,代码行数:29,代码来源:SGLLLog.cs

示例2: Ping

 internal static void Ping()
 {
     return; //NO-OP
     StackFrame sf = new StackTrace(new StackFrame(1, true)).GetFrame(0);
     string file = sf.GetFileName();
     int line = sf.GetFileLineNumber();
     Dictionary<int, ScopedTimerRecord> filedict;
     ScopedTimerRecord linerecord;
     lock (records)
     {
         if (!records.ContainsKey(file))
         {
             records.Add(file, new Dictionary<int, ScopedTimerRecord>());
         }
         filedict = records[file];
     }
     lock(filedict)
     { 
         if (!filedict.ContainsKey(line))
         {
             filedict.Add(line, new ScopedTimerRecord(file, line));
         }
         linerecord = filedict[line];
     }
     linerecord.update();
 }
开发者ID:uml-robotics,项目名称:ROS.NET,代码行数:26,代码来源:ScopedTimer.cs

示例3: SPDException

 /// <summary>
 /// Initializes a new instance of the <see cref="SPDException"/> class.
 /// </summary>
 /// <param name="inner">The inner.</param>
 /// <param name="message">The message.</param>
 /// <param name="url">The URL.</param>
 public SPDException(Exception inner, string message, string url)
     : base(message, inner)
 {
     StackFrame frame = new System.Diagnostics.StackTrace(true).GetFrame(1);
     this.where = "File: " + frame.GetFileName() + Environment.NewLine + "Method: " + frame.GetMethod().Name + Environment.NewLine + "Line: " + frame.GetFileLineNumber() + Environment.NewLine + "Col: " + frame.GetFileColumnNumber();
     this.url = url;
 }
开发者ID:tgassner,项目名称:SPDPatientDocumentation,代码行数:13,代码来源:SPDExceptions.cs

示例4: Append

 public void Append(string m, ROSOUT_LEVEL lvl, int level=1)
 {
     StackFrame sf = new StackTrace(new StackFrame(level,true)).GetFrame(0);
     Log l = new Log {msg = new m.String(m), level = ((byte) ((int) lvl)), name = new m.String(this_node.Name), file = new m.String(sf.GetFileName()), function = new m.String(sf.GetMethod().Name), line = (uint)sf.GetFileLineNumber()};
     string[] advert = this_node.AdvertisedTopics().ToArray();
     l.topics = new m.String[advert.Length];
     for (int i = 0; i < advert.Length; i++)
         l.topics[i] = new m.String(advert[i]);
     lock (queue_mutex)
         log_queue.Enqueue(l);
 }
开发者ID:christlurker,项目名称:ROS.NET,代码行数:11,代码来源:RosOutAppender.cs

示例5: Error

        public Error(Exception ex)
        {
            Message = ex.Message;
            StackTrace = ex.StackTrace;
            Type = ex.GetType().Name;
            Source = ex.Source;

            var frame = new StackTrace(ex, true).GetFrame(0);
            if (frame != null)
            {
                FileName = frame.GetFileName();
                LineNumber = frame.GetFileLineNumber();
                SourceCode = ExceptionHelper.GetSourceFileLines(FileName, Encoding.Default, Source, LineNumber);
            }
        }
开发者ID:Astolfoho,项目名称:Unhandled,代码行数:15,代码来源:Error.cs

示例6: DebugLog

 public void DebugLog(Exception e, DebugLevel Level)
 {
     StackFrame x = new StackTrace(e).GetFrame(0);
     string MethodName = x.GetMethod().Name;
     string Filename = x.GetFileName();
     int Line = x.GetFileLineNumber();
     TDebugInfo db = new TDebugInfo()
     {
         Filename = Filename,
         Level = DebugLevel.F,
         Line = Line,
         MethodName = MethodName,
         Text = e.Message + Environment.NewLine + e.StackTrace,
         Time = DateTime.Now
     };
     if(DebugList.Count > DebugCount)
         DebugList.RemoveAt(0);
     DebugList.Add(db);
     OnError(this, new LogArgs() { DebugInfo = db });
 }
开发者ID:GaryHuang-CL,项目名称:stran,代码行数:20,代码来源:Debug.cs

示例7: Append

 private void Append(string m, ROSOUT_LEVEL lvl, int level)
 {
     StackFrame sf = new StackTrace(new StackFrame(level, true)).GetFrame(0);
     Log logmsg = new Log
     {
         msg = m, name = this_node.Name, file = sf.GetFileName(), function = sf.GetMethod().Name, line = (uint) sf.GetFileLineNumber(), level = ((byte) ((int) lvl)),
         header = new m.Header() { stamp = ROS.GetTime() }
     };
     TopicManager.Instance.getAdvertisedTopics(out logmsg.topics);
     lock (log_queue)
         log_queue.Enqueue(logmsg);
 }
开发者ID:uml-robotics,项目名称:ROS.NET,代码行数:12,代码来源:RosOutAppender.cs

示例8: Write

 /// <summary>
 /// Writes the specified messages to the log.
 /// </summary>
 /// <param name="level">The weight of the message.</param>
 /// <param name="message">The message to log.</param>
 private static void Write(Level level, string message)
 {
     var frm = new StackTrace(2, true).GetFrame(0);
     var log = string.Format("[{0:yyyy-MM-dd HH:mm:ss} / {1}] {2}:{3} / {4}.{5}(): {6}", DateTime.Now, level.ToString().ToUpper(), Path.GetFileName(frm.GetFileName()), frm.GetFileLineNumber(), frm.GetMethod().DeclaringType.FullName, frm.GetMethod().Name, message);
 }
开发者ID:troyb30,项目名称:RS-TV-Show-Tracker,代码行数:10,代码来源:Logger.cs

示例9: MISUSE_BKPT

 internal static RC MISUSE_BKPT()
 {
     var sf = new StackTrace(new StackFrame(true)).GetFrame(0);
     LOG(RC.CANTOPEN, "misuse at line {0} of [{1}]", sf.GetFileLineNumber(), sf.GetFileName());
     return RC.MISUSE;
 }
开发者ID:BclEx,项目名称:GpuStructs,代码行数:6,代码来源:SysEx.cs

示例10: WarnOnIncorrectName

 protected void WarnOnIncorrectName(string name) {
     System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackTrace().GetFrame(1);
     string callerIdMessage = ". Called by {0}.{1}().".Inject(stackFrame.GetFileName(), stackFrame.GetMethod().Name);
     Debug.LogWarning("Name used in PopupList not found: " + name + callerIdMessage);
 }
开发者ID:Maxii,项目名称:CodeEnv.Master,代码行数:5,代码来源:GuiPopupListBase.cs

示例11: IsSecure

        private bool IsSecure(NancyContext context)
        {
            //If we're directly access via a secure scheme everything is ok
            if (context.Request.Url.IsSecure)
                return true;

            //We might be directly accessed via an insecure scheme because a reverse proxy did https termination already, check if a header has been set indicating this
            if (context.Request.Headers.Keys.Contains("X-Forwarded-Protocol") && context.Request.Headers["X-Forwarded-Protocol"].Contains("https"))
                return true;
            if (context.Request.Headers.Keys.Contains("X-Forwarded-Proto") && context.Request.Headers["X-Forwarded-Proto"].Contains("https"))
                return true;

            #if DEBUG
            var frame = new StackTrace(true).GetFrame(0);
            Console.WriteLine("Skipping HTTPS check (DEBUG MODE) {0} Ln{1}", frame.GetFileName(), frame.GetFileLineNumber());
            return true;
            #else
            return false;
            #endif
        }
开发者ID:WildGenie,项目名称:Bastet-Legacy,代码行数:20,代码来源:Bootstrapper.cs

示例12: ErrorToUserLog

        //protected void Page_Error(object sender, EventArgs e)
        //{
        //    //ErrorToUserLog();
        //}

        private void ErrorToUserLog()
        {
            try
            {
                Exception exc = Server.GetLastError();
                string source = Request.QueryString["handler"];
                bool Error = true;
                string ErrorMessage = "";
                if (exc.InnerException != null)
                {
                    ErrorMessage += "Inner Exception Type: ";
                    ErrorMessage += exc.InnerException.GetType().ToString();
                    ErrorMessage += "\n\nInner Exception: ";
                    ErrorMessage += exc.InnerException.Message;
                    ErrorMessage += "\n\nInner Source: ";
                    ErrorMessage += exc.InnerException.Source;
                    if (exc.InnerException.StackTrace != null)
                    {
                        ErrorMessage += "\nInner Stack Trace: ";
                        ErrorMessage += exc.InnerException.StackTrace;
                    }
                }
                var frame = new StackTrace(exc, true).GetFrame(0);
                var sourceFile = frame.GetFileName();
                var lineNumber = frame.GetFileLineNumber();
                ErrorMessage += "\n\nSource File: " + sourceFile + "\nLine Number: " + lineNumber;
                ErrorMessage += "\n\nException Type: ";
                ErrorMessage += exc.GetType().ToString();
                ErrorMessage += "\n\nException: " + exc.Message;
                ErrorMessage += "\n\nSource: " + source;
                ErrorMessage += "\n\nStack Trace: ";
                if (exc.StackTrace != null)
                {
                    ErrorMessage += exc.StackTrace;
                }
                ErrorMessage += "\n\n\n" + exc.ToString();
                ParseObject error = new ParseObject("Error");
                error["errorMessage"] = ErrorMessage;
                if (LoggedIn)
                {
                    error["user"] = PublicUserData.ObjectId;
                }
                error.SaveAsync();
                Response.Redirect("Error");
            }
            catch
            { }
        }
开发者ID:lancelebanoff,项目名称:cognistudy_web,代码行数:53,代码来源:CogniPage.cs

示例13: Log

 // protected because supposes that caller is two levels up
 protected void Log(Level level, object message)
 {
     if (IsLevelEnabled(level))
     {
         StackFrame frame = new System.Diagnostics.StackTrace(true).GetFrame(2);
         string method = frame.GetMethod().Name;
         string file = frame.GetFileName();
         int line = frame.GetFileLineNumber();
         Log(level, message.ToString(), file, line, method);
     }
 }
开发者ID:mbahar94,项目名称:libpxcclr.cs,代码行数:12,代码来源:pxcmloggingservice.cs

示例14: CANTOPEN_BKPT

 internal static RC CANTOPEN_BKPT()
 {
     var sf = new StackTrace(new StackFrame(true)).GetFrame(0);
     LOG(RC.CANTOPEN, "cannot open file at line {0} of [{1}]", sf.GetFileLineNumber(), sf.GetFileName());
     return RC.CANTOPEN;
 }
开发者ID:BclEx,项目名称:GpuStructs,代码行数:6,代码来源:SysEx.cs

示例15: LogException

 internal static void LogException(object sender, Exception e, string currentAction)
 {
     var stackTrace = new StackTrace(e, true).GetFrame(0);
     Log(sender, $"An unhandled exception (type: {e.GetType()}) occurred while {currentAction}. Exception message: \"{e.Message}\"; in file:{stackTrace.GetFileName()}:{stackTrace.GetFileLineNumber()}", LogLevel.Error);
 }
开发者ID:Baggykiin,项目名称:BaggyBot-2,代码行数:5,代码来源:Logger.cs


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