以前用VC做开发 里面有两个宏:
__FILE__ 和 __LINE__ 
C#中有类似的宏吗?

解决方案 »

  1.   

    宏定义必须放在文件的最前面.如#define Debug.
    #define DEBUG
    #define VC_V7
      

  2.   

    using System.Diagnostics;
     public static void WriteErrorToEventLog(string applicationName, string msg)
      {
        StackFrame CallStack = new StackFrame(1, true);
        int lineNumber = CallStack.GetFileLineNumber();
        string msg2 = CallStack.GetFileName() + "\r\n";           // This get calling module's file name and adds to event log.
        msg2 += "Line: " + lineNumber.ToString() + "\r\n";        // This get calling module's line number of call to this function.
        msg2 += msg;
        if (!EventLog.SourceExists(applicationName))
        {
          EventLog.CreateEventSource(applicationName, "Application");
        }
        EventLog.WriteEntry(applicationName, msg2, EventLogEntryType.Error, lineNumber);
      }
    找到了!