Ejemplo n.º 1
0
        public SimpleExceptionDetail(System.Exception e, bool isIncludeStack = true)
            : this()
        {
            Message = e.Message;
            Type = e.GetType().FullName;

            if (!isIncludeStack) return;
            var frames = new StackTrace(e, true).GetFrames();

            if (frames == null || !frames.Any()) return;

            StacktraceDetails = frames.Select(r => new SimpleStacktraceDetail
            {
                File = r.GetFileName(),
                LineNumber = r.GetFileLineNumber(),
                Method = r.GetMethod().Name
            });
        }
Ejemplo n.º 2
0
        public override void Write(string message)
        {
            try
            {
                var frames = new StackTrace().GetFrames();

                // 同じAssemblyのメソッドから呼ばれているか?
                var any = frames.Any(x =>
                    x.GetMethod().DeclaringType != MethodBase.GetCurrentMethod().DeclaringType &&
                    x.GetMethod().ReflectedType.FullName.Contains(this.Name));

                if (!any)
                {
                    return;
                }

                var log =
                    DateTime.Now.ToString("[yyyy/MM/dd HH:mm:ss.fff]") + " " +
                    message;

                this.defaultListener.Write(log);

                if (this.LogTextBox != null)
                {
                    this.LogTextBox.AppendText(log);
                }

                // ログファイルに出力する
                lock (this.logBuffer)
                {
                    this.logBuffer.Add(log);

                    if (this.logBuffer.Count >= 64)
                    {
                        var toWrite = string.Join(string.Empty, this.logBuffer.ToArray());
                        File.AppendAllText(this.logFile, toWrite);
                        this.logBuffer.Clear();
                    }
                }
            }
            catch
            {
            }
        }
Ejemplo n.º 3
0
		public static bool IsUnitTest()
		{
			StackFrame[] frames = new StackTrace().GetFrames();
			return frames.Any(frame => IsTestAttribute(frame) || IsInTestSetUp(frame));
		}
Ejemplo n.º 4
0
 public static bool ContainsUnitTest()
 {
     StackFrame[] frames = new StackTrace().GetFrames();
     return frames != null && frames.Any(IsTestWithoutCategory);
 }