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


C# System.Diagnostics.StackFrame.GetFileName方法代码示例

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


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

示例1: TestContext

 public void TestContext ()
 {
    var queue = new Loggers.Queue();
    var log = new Log(this);
    using (Log.RegisterInstance(
          new Instance()
          {
             Properties = new[]
             {
                "StackFrame.File",
                "StackFrame.Line",
                "StackFrame.Type",
                "StackFrame.Method"
             },
             Logger = queue,
             Buffer = 0,
             Synchronous = true
          }
       )
    )
    {
       var frame = new System.Diagnostics.StackFrame(0, true);
       log.Info("test");
       var evt = queue.Dequeue().Single();
       Assert.AreEqual(evt["StackFrame.File"], frame.GetFileName());
       Assert.AreEqual(evt["StackFrame.Line"], frame.GetFileLineNumber() + 1);
       Assert.AreEqual(evt["StackFrame.Type"], frame.GetMethod().DeclaringType.FullName);
       Assert.AreEqual(evt["StackFrame.Method"], frame.GetMethod().Name);
    }
 }
开发者ID:modulexcite,项目名称:NLogEx,代码行数:30,代码来源:TestStackFrame.cs

示例2: If

		public static void If(bool cond)
		{
			if (!cond)
			{
				/*System.Diagnostics.Debugger.Break();*/
				System.Diagnostics.StackFrame st = new System.Diagnostics.StackFrame(1, true);
				throw new ExceptionLog("Assertion!{0}'{1}':{2} @ {3}", Program.NewLine,
					st.GetFileName(), st.GetMethod(), st.GetFileLineNumber());
			}
		}
开发者ID:CodeAsm,项目名称:open-sauce,代码行数:10,代码来源:Assert.cs

示例3: Test_StackFrame

        public static void Test_StackFrame()
        {
            System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame(skipFrames: 1, fNeedFileInfo: true);

            Trace.WriteLine("create StackFrame(skipFrames: 1, fNeedFileInfo: true) :");
            Trace.WriteLine("  GetMethod().DeclaringType : \"{0}\"", stackFrame.GetMethod().DeclaringType.zGetTypeName());
            Trace.WriteLine("  GetFileName()             : \"{0}\"", stackFrame.GetFileName());
            Trace.WriteLine("  GetFileLineNumber()       : {0}", stackFrame.GetFileLineNumber());
            Trace.WriteLine("  GetFileColumnNumber()     : {0}", stackFrame.GetFileColumnNumber());
        }
开发者ID:labeuze,项目名称:source,代码行数:10,代码来源:Test_Reflection.cs

示例4: SetAttributeValue

        private void SetAttributeValue(GameAttribute attribute, int? key, GameAttributeValue value)
        {
            // error if scripted attribute and is not settable
            if (attribute.ScriptFunc != null && !attribute.ScriptedAndSettable)
            {
                var frame = new System.Diagnostics.StackFrame(2, true);
                Logger.Error("illegal value assignment for GameAttribute.{0} attempted at {1}:{2}",
                    attribute.Name, frame.GetFileName(), frame.GetFileLineNumber());
            }

            if (attribute.EncodingType == GameAttributeEncoding.IntMinMax)
            {
                if (value.Value < attribute.Min.Value || value.Value > attribute.Max.Value)
                    throw new ArgumentOutOfRangeException("GameAttribute." + attribute.Name.Replace(' ', '_'), "Min: " + attribute.Min.Value + " Max: " + attribute.Max.Value + " Tried to set: " + value.Value);
            }
            else if (attribute.EncodingType == GameAttributeEncoding.Float16)
            {
                if (value.ValueF < GameAttribute.Float16Min || value.ValueF > GameAttribute.Float16Max)
                    throw new ArgumentOutOfRangeException("GameAttribute." + attribute.Name.Replace(' ', '_'), "Min: " + GameAttribute.Float16Min + " Max " + GameAttribute.Float16Max + " Tried to set: " + value.ValueF);
            }

            RawSetAttributeValue(attribute, key, value);
        }
开发者ID:venci17,项目名称:mooege,代码行数:23,代码来源:GameAttributeMap.cs

示例5: DoAssert

        static bool DoAssert(string message) {
            if (!s_assert) {
                return false;
            }

            // Skip 2 frames - one for this function, one for
            // the public Assert function that called this function.
            System.Diagnostics.StackFrame frame = new System.Diagnostics.StackFrame(2, true);
            System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(2, true);

            string fileName = frame.GetFileName();
            int lineNumber = frame.GetFileLineNumber();

            string traceFormat;
            if (!string.IsNullOrEmpty(fileName)) {
                traceFormat = "ASSERTION FAILED: {0}\nFile: {1}:{2}\nStack trace:\n{3}";
            }
            else {
                traceFormat = "ASSERTION FAILED: {0}\nStack trace:\n{3}";
            }

            string traceMessage = string.Format(CultureInfo.InvariantCulture, traceFormat, message, fileName, lineNumber, trace.ToString());

            if (!TraceBreak(TAG_ASSERT, traceMessage, null, true)) {
                // If the value of "Assert" is not TagValue.Break, then don't even ask user.
                return false;
            }

            if (s_assertBreak) {
                // If "AssertBreak" is enabled, then always break.
                return true;
            }

            string dialogFormat;
            if (!string.IsNullOrEmpty(fileName)) {
                dialogFormat = 
@"Failed expression: {0}
File: {1}:{2}
Component: {3}
PID={4} TID={5}
Stack trace:
{6}

A=Exit process R=Debug I=Continue";
            }
            else {
                dialogFormat = 
@"Failed expression: {0}
(no file information available)
Component: {3}
PID={4} TID={5}
Stack trace:
{6}

A=Exit process R=Debug I=Continue";
            }

            // GetCurrentThreadId() is marked as obsolete, but this code is only used in debug builds,
            // so it's OK to disable the obsoletion warning.
#pragma warning disable 0618
            string dialogMessage = string.Format(
                CultureInfo.InvariantCulture,
                dialogFormat,
                message,
                fileName, lineNumber,
                COMPONENT,
                NativeMethods.GetCurrentProcessId(), NativeMethods.GetCurrentThreadId(),
                trace.ToString());
#pragma warning restore 0618

            MBResult mbResult = new MBResult();

            Thread thread = new Thread(
                delegate() {
                    for (int i = 0; i < 100; i++) {
                        NativeMethods.MSG msg = new NativeMethods.MSG();
                        NativeMethods.PeekMessage(ref msg, new HandleRef(mbResult, IntPtr.Zero), 0, 0, NativeMethods.PM_REMOVE);
                    }

                    mbResult.Result = NativeMethods.MessageBox(new HandleRef(mbResult, IntPtr.Zero), dialogMessage, PRODUCT + " Assertion",                
                        NativeMethods.MB_SERVICE_NOTIFICATION | 
                        NativeMethods.MB_TOPMOST |
                        NativeMethods.MB_ABORTRETRYIGNORE | 
                        NativeMethods.MB_ICONEXCLAMATION);
                }
            );

            thread.Start();
            thread.Join();

            if (mbResult.Result == NativeMethods.IDABORT) {
                IntPtr currentProcess = NativeMethods.GetCurrentProcess();
                NativeMethods.TerminateProcess(new HandleRef(mbResult, currentProcess), 1);
            }

            return mbResult.Result == NativeMethods.IDRETRY;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:97,代码来源:Debug.cs

示例6: UnreachableException

			public UnreachableException(object case_value)
			{
				System.Diagnostics.StackFrame st = new System.Diagnostics.StackFrame(1, true);
				LogFile.WriteLine("Unreachable case! '{4}'{0}'{1}':{2} @ {3}", Program.NewLine,
					st.GetFileName(), st.GetMethod(), st.GetFileLineNumber(), case_value);
			}
开发者ID:guardian2433,项目名称:open-sauce,代码行数:6,代码来源:Exception.cs

示例7: Log

        //public  void Log(string line)
        //public static void Log(string module, string line, string color = Logging.White)
        public static void Log(string descriptionOfWhere, string line, string color, bool verbose = false)
        {
            try
            {
                //
                // Log location and log names defined here
                //
                Logging.SessionDataCachePath = System.IO.Path.Combine(Logging.PathToCurrentDirectory, "SessionDataCache", CharacterNameForLogs);
                //Logging.Logpath = Logging.PathToCurrentDirectory + "\\log\\" + CharacterNameForLogs + "\\";
                Logging.Logpath = System.IO.Path.Combine(Logging.PathToCurrentDirectory, "log");

                //logpath_s = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\log\\";
                Logging.ConsoleLogPath = System.IO.Path.Combine(Logging.Logpath, CharacterNameForLogs, "Console");
                Logging.ConsoleLogFile = System.IO.Path.Combine(Logging.ConsoleLogPath, string.Format("{0:MM-dd-yyyy}", DateTime.Today) + "-" + CharacterNameForLogs + "-" + "console" + ".log");
                Logging.ConsoleLogPathRedacted = System.IO.Path.Combine(Logging.Logpath, CharacterNameForLogs, "Console");
                Logging.ConsoleLogFileRedacted = System.IO.Path.Combine(Logging.ConsoleLogPath, string.Format("{0:MM-dd-yyyy}", DateTime.Today) + "-" + "redacted" + "-" + "console" + ".log");

                DateTimeForLogs = DateTime.Now;

                if (verbose) //tons of info
                {
                    //
                    // verbose text logging - with line numbers, filenames and Methods listed ON EVERY LOGGING LINE - this is ALOT more detail
                    //
                    System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame(1, true);
                    descriptionOfWhere += "-[line" + sf.GetFileLineNumber().ToString() + "]in[" + System.IO.Path.GetFileName(sf.GetFileName()) + "][" + sf.GetMethod().Name + "]";
                }

                _colorLogLine = line;
                Logging.RedactedColorLogLine = String.Format("{0:HH:mm:ss} {1}", DateTimeForLogs, Logging.Orange + "[" + Logging.Yellow + descriptionOfWhere + Logging.Orange + "] " + color + FilterSensitiveInfo(_colorLogLine));  //In memory Console Log with sensitive info redacted

                _plainLogLine = FilterColorsFromLogs(line);
                Logging.RedactedPlainLogLine = String.Format("{0:HH:mm:ss} {1}", DateTimeForLogs, "[" + descriptionOfWhere + "] " + FilterSensitiveInfo(_plainLogLine) + "\r\n");  //In memory Console Log with sensitive info redacted
                Logging.ExtConsole = Logging.RedactedPlainLogLine;

                //
                // Log To Screen
                //
                //if (Logging.UseInnerspace) //Write logging entry to the Innerspace Console window
                //{
                    InnerSpace.Echo(Logging.RedactedColorLogLine);
                //}
                //else // Write directly to the EVE Console window (if you want to see this you must be running EXEFile.exe without the /noconsole switch)
                //{
                //    Console.Write(Logging.RedactedPlainLogLine);
                //}

                //
                // Log To File
                //
                if (!Logging.ConsoleLogOpened)
                {
                    PrepareConsoleLog();
                }

                if (Logging.ConsoleLogOpened)
                {
                    WriteToConsoleLog();
                }
            }
            catch (Exception exception)
            {
                BasicLog(descriptionOfWhere, exception.Message);
            }
        }
开发者ID:isxGames,项目名称:QuestorISX,代码行数:67,代码来源:Logging.cs

示例8: Log

        //public  void Log(string line)
        //public static void Log(string module, string line, string color = Logging.White)
        public static void Log(string module, string line, string color, bool verbose = false)
        {
            try
            {

                DateTimeForLogs = DateTime.Now;

                if (verbose) //tons of info
                {
                    //
                    // verbose text logging - with line numbers, filenames and Methods listed ON EVERY LOGGING LINE - this is ALOT more detail
                    //
                    System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame(1, true);
                    module += "-[line" + sf.GetFileLineNumber().ToString() + "]in[" + System.IO.Path.GetFileName(sf.GetFileName()) + "][" + sf.GetMethod().Name + "]";
                }

                _colorLogLine = line;
                Logging.redactedColorLogLine = String.Format("{0:HH:mm:ss} {1}", DateTimeForLogs, "[" + module + "] " + FilterSensitiveInfo(_plainLogLine) + "\r\n");  //In memory Console Log with sensitive info redacted

                _plainLogLine = FilterColorsFromLogs(line);

                Logging.redactedPlainLogLine = String.Format("{0:HH:mm:ss} {1}", DateTimeForLogs, "[" + module + "] " + FilterSensitiveInfo(_plainLogLine) + "\r\n");  //In memory Console Log with sensitive info redacted

                Logging.ExtConsole = Logging.redactedPlainLogLine;

                if (TextBoxWriter != null)
                {
                    TextBoxWriter.Write(Logging.redactedPlainLogLine);
                }

                if (Logging.tryToLogToFile)
                {
                    if (Logging.SaveConsoleLog)//(Settings.Instance.SaveConsoleLog)
                    {
                        if (!Logging.ConsoleLogOpened)
                        {
                            //
                            // begin logging to file
                            //
                            if (Logging.ConsoleLogPath != null && Logging.ConsoleLogFile != null)
                            {
                                if (!string.IsNullOrEmpty(Logging.ConsoleLogFile))
                                {
                                    Directory.CreateDirectory(Logging.ConsoleLogPath);
                                    if (Directory.Exists(Logging.ConsoleLogPath))
                                    {
                                        Logging.ConsoleLogOpened = true;
                                    }
                                    line = "";
                                }
                                else
                                {
                                    line = "Logging: Unable to write log to file yet as: ConsoleLogFile is not yet defined";
                                }
                            }
                        }

                        if (Logging.ConsoleLogOpened)
                        {
                            //
                            // log file ready: add next logging entry...
                            //
                            //
                            // normal text logging
                            //
                            if (Logging.ConsoleLogFile != null && !verbose) //normal
                            {
                                File.AppendAllText(System.IO.Path.Combine(Logging.ConsoleLogPath, Logging.ConsoleLogFile), Logging.redactedPlainLogLine); //Write In Memory Console log to File
                            }

                            //
                            // redacted text logging - sensitive info removed so you can generally paste the contents of this log publicly w/o fear of easily exposing user identifiable info
                            //
                            if (Logging.ConsoleLogFileRedacted != null)
                            {
                                File.AppendAllText(System.IO.Path.Combine(Logging.ConsoleLogPath, Logging.ConsoleLogFileRedacted), Logging.redactedPlainLogLine);               //Write In Memory Console log to File
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                BasicLog(module, exception.Message);
            }
        }
开发者ID:tjuckett,项目名称:OmniEve,代码行数:88,代码来源:Logging.cs


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