Beispiel #1
0
 public static void LogMethodExit(
     LOGSEVERITY eSeverity = LOGSEVERITY.Information)
 {
     var sf = new StackTrace(true).GetFrame(1);
     var method = sf.GetMethod();
     Log("exit.", eSeverity, sf.GetMethod().Name, sf.GetFileLineNumber(), method.ReflectedType.Name);
 }
        protected static void DisplayTestResults(RunSummary summary)
        {
            var caller =
                new StackTrace().GetFrames()
                    .First(f => typeof(NServiceBusPerformanceTest).IsAssignableFrom(f.GetMethod().DeclaringType.BaseType));

            var testCategory =
                caller.GetMethod()
                    .DeclaringType.Namespace.Replace(typeof(NServiceBusPerformanceTest).Namespace + ".", "");
            var testCase = caller.GetMethod().Name;

            var c = (PerformanceTestContext)summary.RunDescriptor.ScenarioContext;

            var messagesPerSecondsProcessed = c.NumberOfTestMessages/
                                              (c.LastMessageProcessedAt - c.FirstMessageProcessedAt).TotalSeconds;

            Console.Out.WriteLine("Results: {0} messages, {1} msg/s", c.NumberOfTestMessages,
                messagesPerSecondsProcessed);

            using (var file = new StreamWriter(".\\PerformanceTestResults.txt", true))
            {
                file.WriteLine(string.Join(";", summary.RunDescriptor.Key, testCategory, testCase,
                    c.NumberOfTestMessages, messagesPerSecondsProcessed));
            }

            Console.Out.WriteLine("##teamcity[buildStatisticValue key='{0}' value='{1:0}']",
                summary.RunDescriptor.Key + "." + testCategory + "." + testCase, messagesPerSecondsProcessed);
        }
Beispiel #3
0
 /// <summary>
 /// Submit an exception online.
 /// </summary>
 /// <param name="e">
 /// The Exception
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 internal static bool SumbitException(Exception e)
 {
     var err = e.ToString();
     var ass = Assembly.GetCallingAssembly().GetName().Name;
     var ver = Assembly.GetCallingAssembly().GetName().Version.ToString();
     var st = new StackTrace().GetFrame(1);
     var name = st.GetMethod().ReflectedType.FullName + st.GetMethod().Name;
     return SendPost(err, ass, ver, name);
 }
        /// <summary>
        /// Writes the specified log level.
        /// </summary>
        /// <param name="logLevel">Used level.</param>
        /// <param name="msg">Message.</param>
        /// <param name="exception">The exception (or null).</param>
        public override void Write(LogLevel logLevel, string msg, Exception exception)
        {
            var frame = new StackTrace(SkipFrameCount).GetFrame(0);
            var caller = frame.GetMethod().ReflectedType.Name + "." +
                         frame.GetMethod().Name + "():" + frame.GetFileLineNumber();

            System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " " + caller.PadRight(50) + logLevel.ToString().PadRight(10) + msg);
            if (exception != null)
                System.Diagnostics.Debug.WriteLine(BuildExceptionDetails(exception, 4));
        }
        /// <summary>
        /// Writes the specified log level.
        /// </summary>
        /// <param name="logLevel">Used level.</param>
        /// <param name="msg">Message.</param>
        /// <param name="exception">The exception (or null).</param>
        public override void Write(LogLevel logLevel, string msg, Exception exception)
        {
            var frame = new StackTrace(SkipFrameCount).GetFrame(0);
            var caller = frame.GetMethod().ReflectedType.Name + "." +
                         frame.GetMethod().Name + "():" + frame.GetFileLineNumber();

            ConsoleColor color = Console.ForegroundColor;
            Console.ForegroundColor= GetColor(logLevel);
            Console.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " " + caller.PadRight(50) + logLevel.ToString().PadRight(10) + msg);
            if (exception != null)
                Console.WriteLine(BuildExceptionDetails(exception, 4));
            Console.ForegroundColor = color;
        }
        /// <summary>
        /// Prints a red, error line of log, together with timestamp and method name.
        /// </summary>
        /// <param name="logText">The log line to be printed.</param>
        public static void WriteError(string logText)
        {
            DateTime _DTN = DateTime.Now;
            StackFrame _SF = new StackTrace().GetFrame(1);

            Console.Write("[" + _DTN.ToLongTimeString() + ":" + _DTN.Millisecond.ToString() + "] [");
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write(_SF.GetMethod().ReflectedType.Name + "." + _SF.GetMethod().Name);
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.Write("] » ");
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine(logText);
            Console.ForegroundColor = ConsoleColor.Gray;
        }
Beispiel #7
0
 public static String ThisMethod()
 {
     StackFrame sf = new StackTrace().GetFrame(1);
     MethodBase method = sf.GetMethod();
     String sep = ( method.IsStatic ? "::" : "." );
     return String.Format( "{0}{1}{2}$ ", method.DeclaringType.Name, sep, method.Name);
 }
        private static String executeShell()
        {
            PlatformID currentPlatform = Environment.OSVersion.Platform;
            var stackFrame = new StackTrace(1).GetFrame(0);
            var method = stackFrame.GetMethod();
            var shellCmdAttr = method.GetCustomAttributes(typeof(ShellCmdAttribute), false)
                .Cast<ShellCmdAttribute>()
                .Where(t => t.PlatformID == currentPlatform).FirstOrDefault();
            if (shellCmdAttr == null)
                return null;

            String programName = shellCmdAttr.Program;
            String arguments = shellCmdAttr.Arguments;

            var process = new Process();
            var psi = process.StartInfo;
            psi.FileName = programName;
            psi.Arguments = arguments;

            psi.UseShellExecute = false;
            psi.RedirectStandardOutput = true;

            process.Start();
            var content = process.StandardOutput.ReadToEnd();
            process.WaitForExit();

            var match = shellCmdAttr.Regex.Match(content);
            if (match == null || !match.Success)
                return null;
            var value = match.Groups["value"].Value;
            return value;
        }
Beispiel #9
0
        public static Type GetCallingType()
        {
            if (EnvironmentHelper.IsProcessHostedByTool)
            {
                return typeof(object);
            }


//#if NETFX_CORE
//            var type = typeof(object);
//#else
//            var stackTrace = StackTraceHelper.GetStackTrace();
//            var stackFrame = stackTrace.GetFrame(2);
//            var type = stackFrame.GetMethod().DeclaringType;
//#endif

#if NET
            var frame = new StackFrame(2, false);
            var type = frame.GetMethod().DeclaringType;
#elif NETFX_CORE
            var type = typeof(object);
#else
            var frame = new StackTrace().GetFrame(2);
            var type = frame.GetMethod().DeclaringType;
#endif

            return type;
        }
Beispiel #10
0
        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 });
            }
        }
 /// <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;
 }
Beispiel #12
0
 public static void LogMethodException(
     string exception,
     LOGSEVERITY eSeverity = LOGSEVERITY.Error)
 {
     var sf = new StackTrace(true).GetFrame(1);
     var method = sf.GetMethod();
     Log(string.Format("Got exception = {0}!", exception), eSeverity, method.Name, sf.GetFileLineNumber(), method.ReflectedType.Name);
 }
        internal static void GenerateExceptionTest(this Exception ex)
        {
            var sb = new StringBuilder();
            GenerateExceptionTest(ex, 0, sb);

            var trace = new StackTrace().GetFrame(1);
            File.WriteAllText(@"d:\" + trace.GetMethod().Name, sb.ToString());
        }
    protected override void OnCheckboxStateChange(bool state) {
        System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackTrace().GetFrame(0);
        Debug.Log("{0}.{1}() method called.".Inject(GetType(), stackFrame.GetMethod().Name));

        // UNDONE
        // playerPrefsMgr.IsPauseOnLoadEnabled = state;
        // Debug.LogWarning("OnPauseAfterReloadOptionChange() is not yet fully implemented.");
    }
Beispiel #15
0
        public static void Error(string format, params object[] pParams)
        {
            var frame = new StackTrace().GetFrame(1);
            var final = string.Format("[{0}] - {1}:{2} - ", DateTime.Now, frame.GetMethod().ReflectedType.FullName, frame.GetMethod().Name);
            lock (_oLock)
            {
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                _textWriter.Write(final);
                Console.ForegroundColor = ConsoleColor.Red;
                _textWriter.WriteLine(format, pParams);

               //     _streamWriter.Write(final);
            //    _streamWriter.WriteLine(format, pParams);

               //     _streamWriter.Flush();
                _textWriter.Flush();
            }
        }
Beispiel #16
0
 public void LogEnd()
 {
     if (Log.IsInfoEnabled)
     {
         System.Diagnostics.StackFrame f = new System.Diagnostics.StackTrace().GetFrame(1);
         System.Reflection.MethodBase  m = f.GetMethod();
         Debug(m.DeclaringType.Name + "." + m.Name + "() END ----------------------");
     }
 }
Beispiel #17
0
 string MethodName(int stackIndex)
 {
     string methodName = "";
     if(Regex.IsMatch(filters.LogPattern, "%method")) {
         System.Diagnostics.StackFrame frame = new System.Diagnostics.StackTrace().GetFrames()[stackIndex];
         methodName = frame.GetMethod().Name;
     }
     return methodName;
 }
Beispiel #18
0
 public DateTime LogStart()
 {
     if (Log.IsInfoEnabled)
     {
         System.Diagnostics.StackFrame f = new System.Diagnostics.StackTrace().GetFrame(1);
         System.Reflection.MethodBase  m = f.GetMethod();
         Debug(m.DeclaringType.Name + "." + m.Name + "() START --------------------");
     }
     return(DateTime.Now);
 }
Beispiel #19
0
        protected string ReadExpected()
        {
            var frame = new StackTrace(1).GetFrame(0);

            // get the target test method.
            var targetMethod = frame.GetMethod();

            var expected = ReadResult(targetMethod.Name);
            return expected;
        }
        /// <summary>
        /// Initializes a logger with the current class as name.
        /// It searches the stackframe for this name, use GetLogger(string) for better performance.
        /// </summary>
        /// <returns>A new instance of a Logger.</returns>
        public static Logger GetLogger()
        {
            // Get the caller of this method
            StackFrame stackFrame = new StackTrace().GetFrame(1);

            // Use the name of that class as this loggers name
            string className = stackFrame.GetMethod().ReflectedType.FullName;

            return GetLogger(className);
        }
Beispiel #21
0
 public string GetCallFunction()
 {
     string name = string.Empty;
     StackFrame frame = new StackTrace().GetFrame(2);
     if (frame != null)
     {
         name = frame.GetMethod().Name;
     }
     return name;
 }
 // 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);
     }
 }
Beispiel #23
0
 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);
 }
Beispiel #24
0
    string MethodName(int stackIndex)
    {
        string methodName = "";

        if (Regex.IsMatch(filters.LogPattern, "%method"))
        {
            System.Diagnostics.StackFrame frame = new System.Diagnostics.StackTrace().GetFrames()[stackIndex];
            methodName = frame.GetMethod().Name;
        }
        return(methodName);
    }
Beispiel #25
0
        private string GetCallerName()
        {
            var externalCaller = new StackTrace().GetFrames().Where(o => o.GetMethod().DeclaringType != GetType()).FirstOrDefault();

            if (externalCaller != null)
            {
                var method = externalCaller.GetMethod();
                return string.Concat(method.DeclaringType.Name, ".", method.Name);
            }

            return string.Empty;
        }
Beispiel #26
0
        public static Type GetCallingType()
        {
#if NET
            var frame = new StackFrame(2, false);
            var type = frame.GetMethod().DeclaringType;
#elif NETFX_CORE || PCL
            var type = typeof(object);
#else
            var frame = new StackTrace().GetFrame(2);
            var type = frame.GetMethod().DeclaringType;
#endif

            return type;
        }
    protected override void OnPopupListSelectionChange(string item) {
        GameSpeed speed;
        if (!Enums<GameSpeed>.TryParse(item, true, out speed)) {
            WarnOnIncorrectName(item);
            return;
        }

        System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackTrace().GetFrame(0);
        Debug.Log("{0}.{1}() method called.".Inject(GetType(), stackFrame.GetMethod().Name));

        // UNDONE
        //playerPrefsMgr.GameSpeedOnLoad = speed;
        //Debug.LogWarning("GameSpeedOnLoadOption is not yet fully implemented.");
    }
    private static void DoTrue(bool condition, string message)
    {
        if (Debug.isDebugBuild && !condition)
        {
            System.Diagnostics.StackFrame f = new System.Diagnostics.StackTrace(true).GetFrame(2);
            string new_message = "Assertion failed in " + f.GetMethod() + " (" + f.GetFileName() + ":" + f.GetFileLineNumber() + ")";
            if (!string.IsNullOrEmpty(message))
            {
                new_message += "\n" + message;
            }

            Debug.Assert(condition, new_message);
            HaltWhen(!condition);
        }
    }
Beispiel #29
0
        public static void WriteDCError(string logText)
        {
            try
            {
                System.IO.FileStream Writer = new System.IO.FileStream("DC.err", System.IO.FileMode.Append, System.IO.FileAccess.Write);
                byte[] Msg = System.Text.ASCIIEncoding.ASCII.GetBytes(logText + "\r\n\r\n");
                Writer.Write(Msg, 0, Msg.Length);
            }
            catch (Exception eX) { Out.WritePlain(eX.Message); }
            wait();
            bwait = true;
            DateTime _DTN = DateTime.Now;
            StackFrame _SF = new StackTrace().GetFrame(1);

            Console.Write("[" + _DTN.ToLongTimeString() + ":" + _DTN.Millisecond.ToString() + "] [");
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write(_SF.GetMethod().ReflectedType.Name + "." + _SF.GetMethod().Name);
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.Write("] » ");
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("Look in DC.err for the disconnection error.");
            Console.ForegroundColor = ConsoleColor.Gray;
            bwait = false;
        }
    protected override void OnPopupListSelectionChange(string item) {
        UniverseSize size;
        if (!Enums<UniverseSize>.TryParse(item, true, out size)) {
            WarnOnIncorrectName(item);
            return;
        }

        System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackTrace().GetFrame(0);
        Debug.Log("{0}.{1}() method called.".Inject(GetType(), stackFrame.GetMethod().Name));
        if (size != UniverseSize.Normal) {
            // FIXME
            Debug.LogError("Universe Size Change is only allowed during New Game Setup.");
            return;
        }
        playerPrefsMgr.SizeOfUniverse = size;
    }
Beispiel #31
0
        internal static void Log(object instance,
            Expression expression)
        {
            StackFrame frame = new StackTrace().GetFrame(1);
            MethodBase method = frame.GetMethod();
            Type type = instance.GetType();
            string typeName = type.Name;

            if (type.IsGenericType)
            {
                Type[] genericArgs = type.GetGenericArguments();
                typeName = typeName.Replace("`1", "<"+genericArgs[0].Name+">");
            }
            Console.WriteLine("{0}.{1}", typeName, method.Name);

            Console.WriteLine("Expression={0}", expression);
            Console.WriteLine();
        }
        internal void CheckError()
        {
            //return;
            #if DEBUG
            return;//TODO:

            var       frame = new System.Diagnostics.StackTrace(true).GetFrame(1);
            ErrorCode code  = ErrorCode.InvalidValue;
            ThreadingHelper.BlockOnUIThread(() =>
            {
                code = GL.GetError();
                if (code != ErrorCode.NoError)
                {
                    string filename = frame.GetFileName();
                    int line        = frame.GetFileLineNumber();
                    string method   = frame.GetMethod().Name;
                    Debug.WriteLine("[GL] " + filename + ":" + method + " - " + line.ToString() + ":" + code.ToString());
                }
            }, true);
            #endif
        }
Beispiel #33
0
        public static void Write(String message, LogLevel level, Boolean consolewrite = true)
        {
            string caller = "ChestControl";

            StackFrame frame = new StackTrace().GetFrame(2);
            if (frame != null)
            {
                var meth = frame.GetMethod();
                if (meth != null)
                    if (meth.DeclaringType != null)
                        caller = meth.DeclaringType.Name;
            }

            logWriter.WriteLine(string.Format("{0} - {1}: {2}: {3}",
                                               DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
                                               caller, level.ToString().ToUpper(), message));
            logWriter.Flush();
            if (consolewrite)
                Console.WriteLine(string.Format("{0}: {1}: {2}",
                    caller, level.ToString().ToUpper(), message));
        }
Beispiel #34
0
 private static MethodBase GetCaller()
 {
     var stackFrame = new StackTrace().GetFrame(3);
       return stackFrame.GetMethod();
 }
Beispiel #35
0
        /// <summary>
        /// Internal method which writes a message directly to the log file.
        /// </summary>
        private static void Write(String message, LogLevel level)
        {
            if (!MayWriteType(level))
            {
                return;
            }

            string caller = "TShock";

            StackFrame frame = new StackTrace().GetFrame(2);
            if (frame != null)
            {
                var meth = frame.GetMethod();
                if (meth != null)
                    caller = meth.DeclaringType.Name;
            }

            try
            {
                _logWriter.WriteLine(string.Format("{0} - {1}: {2}: {3}",
                                   DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
                                   caller, level.ToString().ToUpper(), message));
                _logWriter.Flush();
            }
            catch (ObjectDisposedException)
            {
                Console.WriteLine("Unable to write to log as log has been disposed.");
                Console.WriteLine("{0} - {1}: {2}: {3}",
                                   DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
                                   caller, level.ToString().ToUpper(), message);
            }
        }
 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);
 }
Beispiel #37
0
 private void LogPerformace(string otherInfo, DateTime started, DateTime ended, int frames)
 {
     System.Diagnostics.StackFrame f = new System.Diagnostics.StackTrace().GetFrame(frames);
     System.Reflection.MethodBase  m = f.GetMethod();
     Info(String.Format("PERFLOG: {0},{1},{2},{3},{4},{5}", m.DeclaringType.Name, m.Name, otherInfo, started.ToLongTimeString(), ended.ToLongTimeString(), (ended - started).Milliseconds.ToString()));
 }