本文整理汇总了C#中System.Diagnostics.StackFrame.GetFileLineNumber方法的典型用法代码示例。如果您正苦于以下问题:C# System.Diagnostics.StackFrame.GetFileLineNumber方法的具体用法?C# System.Diagnostics.StackFrame.GetFileLineNumber怎么用?C# System.Diagnostics.StackFrame.GetFileLineNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.StackFrame
的用法示例。
在下文中一共展示了System.Diagnostics.StackFrame.GetFileLineNumber方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例2: ArrayAttribute
public ArrayAttribute(NsNode parent, XmlNode xml)
: this(parent, null, null)
{
if (!FromXml(xml))
{
System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame(1, true);
throw new AttributeXmlFormatException(this, xml, "Failed to read xml (" + stackFrame.GetMethod() + " ln: " + stackFrame.GetFileLineNumber() +")");
}
}
示例3: 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());
}
}
示例4: 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());
}
示例5: 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);
}
示例6: 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;
}
示例7: w
private void w()
{
System.Diagnostics.StackFrame s = new System.Diagnostics.StackFrame(1, true);
System.Console.WriteLine(s.GetFileLineNumber());
}
示例8: 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);
}
示例9: 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);
}
}
示例10: Dispose
public void Dispose()
{
// February 2013 - We cannot call the log during dispose because we do not know if the Log is still acgtive
//NOTE: Expensive debugging information, remove when done with
bool f = false;
if (f == true) {
System.Diagnostics.StackFrame frame = new System.Diagnostics.StackFrame (1);
System.Diagnostics.StackFrame frame2 = new System.Diagnostics.StackFrame (2);
System.Diagnostics.StackFrame frame3 = new System.Diagnostics.StackFrame (3);
string callingfunc = String.Format ("[{0}.{1}]", frame.GetFileLineNumber (), frame.GetMethod ().Name);
string callingfunc2 = String.Format ("[{0}.{1}]", frame2.GetFileLineNumber (), frame2.GetMethod ().Name);
string callingfunc3 = String.Format ("[{0}.{1}]", frame2.GetFileLineNumber (), frame2.GetMethod ().Name);
// lg.Instance.Line ("LayoutDatabase->Dispose", ProblemType.MESSAGE,
// String.Format ("Dispose called for {0} with a list this long {1} called by {2} and {3} and {4} ",
// LayoutGUID, this.dataForThisLayout.Count, callingfunc, callingfunc2, callingfunc3));
} else {
//lg.Instance.Line ("LayoutDatabase->Dispose", ProblemType.MESSAGE, String.Format ("SHORT DEBUG MESSAGE: Dispose called for {0} with a list this long {1}",
// LayoutGUID, this.dataForThisLayout.Count));
}
//NewMessage.Show (String.Format ("Dispose called for {0} with a list this long {1} ", LayoutGUID, this.dataForThisLayout.Count));
if (dataForThisLayout != null) {
dataForThisLayout = null;
}
}
示例11: OnPaintBackground
protected override void OnPaintBackground( PaintEventArgs e )
{
if ( Bounds.Width > 0 && Bounds.Height > 0 && Visible )
{
try
{
Rectangle rect = new Rectangle(0, 0, Bounds.Width, Bounds.Height);
Graphics g = e.Graphics;
g.SetClip(e.ClipRectangle);
if (BackgroundImage == null)
{
SolidBrush solidBrush = new SolidBrush(BackColor);
g.FillRectangle(solidBrush, rect);
solidBrush.Dispose();
}
else
{
g.DrawImage(BackgroundImage, rect, 0, 0, BackgroundImage.Width, BackgroundImage.Height, GraphicsUnit.Pixel);
}
}
catch (Exception exception)
{
System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame(true);
Console.WriteLine("\nException: {0}, \n\t{1}, \n\t{2}, \n\t{3}\n", this.GetType().ToString(), stackFrame.GetMethod().ToString(), stackFrame.GetFileLineNumber(), exception.Message);
}
}
}
示例12: OnPaint
protected override void OnPaint( PaintEventArgs e )
{
if ( Bounds.Width > 0 && Bounds.Height > 0 && Visible )
{
try
{
Graphics g = e.Graphics;
g.SetClip(e.ClipRectangle);
g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
float nClientHeight = ClientRectangle.Height;
//start the text two thirds down:
m_nTextOffsetY = Convert.ToInt32(Math.Ceiling(((nClientHeight / 3) * 2))) + m_nLeading;
if (TitleString != string.Empty)
{
Font fontTitle = new Font(Font, FontStyle.Bold);
SizeF sizeF = g.MeasureString(TitleString, fontTitle, ClientRectangle.Width, m_stringFormat);
m_nTextOffsetY += Convert.ToInt32(Math.Ceiling(sizeF.Height));
RectangleF rectangleF = new RectangleF(ClientRectangle.Left + m_nTextOffsetX, ClientRectangle.Top + m_nTextOffsetY, sizeF.Width, sizeF.Height);
SolidBrush brushFont = new SolidBrush(ForeColor);
g.DrawString(TitleString, fontTitle, brushFont, rectangleF, m_stringFormat);
brushFont.Dispose();
fontTitle.Dispose();
m_nTextOffsetY += m_nLeading;
}
if (CommentaryString != string.Empty)
{
SizeF sizeF = g.MeasureString(CommentaryString, Font, ClientRectangle.Width, m_stringFormat);
m_nTextOffsetY += Convert.ToInt32(Math.Ceiling(sizeF.Height));
RectangleF rectangleF = new RectangleF(ClientRectangle.Left + m_nTextOffsetX, ClientRectangle.Top + m_nTextOffsetY, sizeF.Width, sizeF.Height);
SolidBrush brushFont = new SolidBrush(ForeColor);
g.DrawString(CommentaryString, Font, brushFont, rectangleF, m_stringFormat);
brushFont.Dispose();
}
}
catch (Exception exception)
{
System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame(true);
Console.WriteLine("\nException: {0}, \n\t{1}, \n\t{2}, \n\t{3}\n", this.GetType().ToString(), stackFrame.GetMethod().ToString(), stackFrame.GetFileLineNumber(), exception.Message);
}
}
}
示例13: 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);
}
}
示例14: FromXml
public bool FromXml(System.Xml.XmlNode xml)
{
if (xml.Attributes == null || xml.Attributes.Count < 3)
return false;
PlyID = -1;
Start = PointF.Empty;
End = PointF.Empty;
foreach (XmlAttribute atr in xml.Attributes)
{
if (atr.Name == "Start")
{
try
{
string[] data = null;
data = atr.Value.Split(new Char[] { ',' });
float startx = (float)(Convert.ToDouble(data[0]) * 1000);
float starty = (float)(Convert.ToDouble(data[1]) * 1000);
if (Math.Abs(startx) == float.PositiveInfinity || Math.Abs(starty) == float.PositiveInfinity)
{
System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame(1, true);
throw (new Exception("Error (" + stackFrame.GetMethod() + " ln: " + stackFrame.GetFileLineNumber() +")"));
}
Start = new PointF(startx, starty);
}
catch
{
Start = PointF.Empty;
throw (new Exception("Error converting value from 3di file: " + this.ToString()));
}
}
else if (atr.Name == "End")
{
try
{
string[] data = null;
data = atr.Value.Split(new Char[] { ',' });
float endx = (float)(Convert.ToDouble(data[0]) * 1000);
float endy = (float)(Convert.ToDouble(data[1]) * 1000);
if (Math.Abs(endx) == float.PositiveInfinity || Math.Abs(endy) == float.PositiveInfinity )
throw (new Exception());
End = new PointF(endx, endy);
}
catch
{
End = PointF.Empty;
throw (new Exception("Error converting value from 3di file: " + this.ToString()));
}
}
else if (atr.Name == "PlyID")
{
int i = 0;
try
{
i = Convert.ToInt32(atr.Value);
PlyID = i;
}
catch
{
PlyID = -1;
}
}
}
//check for a 3d triangle strip
if (xml.ChildNodes.Count != 0)
{
ReadTriStrip(xml);
}
return Start != null && End != null && PlyID != -1;
}