Ejemplo n.º 1
0
        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Exception ex = (Exception)e.ExceptionObject;

            // write it to a log file
            StringBuilder sb = new StringBuilder();

            sb.Append(string.Format("{0} at {1}\r\n", ex.GetType().FullName, DateTime.Now.ToString("MM/dd/yy hh:mm:ss")));
            sb.Append(string.Format("Runtime {0} terminating\r\n", e.IsTerminating ? "true" : "false"));
            sb.Append(string.Format("Message: {0}\r\n", ex.Message));
            sb.Append(string.Format("Stack trace: {0}\r\n", ex.StackTrace));

            Trace2.WriteLine(sb.ToString());

            if (Debugger.IsAttached)
            {
                Debugger.Break();
            }
            else
            {
                string       exceptionPath = Path.Combine(AppPath, EXCEPTION_FILE_NAME);
                StreamWriter writer        = File.Exists(exceptionPath) ? File.AppendText(exceptionPath) : File.CreateText(exceptionPath);

                writer.Write(sb.ToString());
                writer.Close();
            }
        }
Ejemplo n.º 2
0
        private async Task OnValidSubmit(EditContext context)
        {
            Trace2.Log("OnValidSubmit 回调委托: Starting ...");
            await Task.Delay(3000);

            Trace2.Log("OnValidSubmit 回调委托: Done!");
        }
        public void TestMethod1()
        {
            var target = new StringBuilder();

            using (var stream = new StringWriter(target))
            {
                var testOutput = "Hello World";
                var listener   = new TextWriterTraceListener(stream);

                Trace2.Write(testOutput);
                Assert.AreEqual(string.Empty, target.ToString());

                Trace2.Listeners.Add(listener);
                Trace2.Write(testOutput);
                Assert.AreEqual(testOutput, target.ToString());
            }
        }
Ejemplo n.º 4
0
        private void HandleException(Exception ex)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(string.Format("{0} at {1}\r\n", ex.GetType().FullName, DateTime.Now.ToString("MM/dd/yy hh:mm:ss")));
            sb.Append(string.Format("Message: {0}\r\n", ex.Message));
            sb.Append(string.Format("Stack trace: {0}\r\n", ex.StackTrace));

            Trace2.WriteLine(sb.ToString());

            if (Debugger.IsAttached)
            {
                Debugger.Break();
            }
            else
            {
                string       exceptionPath = Path.Combine(Program.AppPath, "exceptionlog.txt");
                StreamWriter writer        = File.Exists(exceptionPath) ? File.AppendText(exceptionPath) : File.CreateText(exceptionPath);

                writer.Write(sb.ToString());
                writer.Close();
            }
        }
Ejemplo n.º 5
0
 private Task OnInvalidSubmit(EditContext context)
 {
     Trace2.Log("OnInvalidSubmit 回调委托");
     return(Task.CompletedTask);
 }
Ejemplo n.º 6
0
 private Task OnClick2(MenuItem item)
 {
     Trace2.Log($"菜单点击项: {item.Text}");
     return(Task.CompletedTask);
 }
Ejemplo n.º 7
0
 private Task OnSearch2(string searchText)
 {
     Trace2.Log($"SearchText: {searchText}");
     return(Task.CompletedTask);
 }
Ejemplo n.º 8
0
 private Task OnSelectedItemsChanged8(IEnumerable <SelectedItem> items)
 {
     Trace2.Log($"选中项集合:{string.Join(",", items.Select(i => i.Value))}");
     return(Task.CompletedTask);
 }