improve:改进了日志输出
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace Ink_Canvas.Helpers
|
||||
{
|
||||
@@ -14,24 +16,19 @@ namespace Ink_Canvas.Helpers
|
||||
|
||||
public static void NewLog(Exception ex)
|
||||
{
|
||||
|
||||
if (ex == null) return;
|
||||
var stackTrace = ex.StackTrace ?? "<no stack trace>";
|
||||
var msg = $"[Exception] Type: {ex.GetType().FullName}\nMessage: {ex.Message}\nStackTrace: {stackTrace}";
|
||||
if (ex.InnerException != null)
|
||||
{
|
||||
msg += $"\nInnerException: {ex.InnerException.GetType().FullName} - {ex.InnerException.Message}\n{ex.InnerException.StackTrace}";
|
||||
}
|
||||
WriteLogToFile(msg, LogType.Error);
|
||||
}
|
||||
|
||||
public static void WriteLogToFile(string str, LogType logType = LogType.Info)
|
||||
{
|
||||
string strLogType = "Info";
|
||||
switch (logType)
|
||||
{
|
||||
case LogType.Event:
|
||||
strLogType = "Event";
|
||||
break;
|
||||
case LogType.Trace:
|
||||
strLogType = "Trace";
|
||||
break;
|
||||
case LogType.Error:
|
||||
strLogType = "Error";
|
||||
break;
|
||||
}
|
||||
string strLogType = logType.ToString();
|
||||
try
|
||||
{
|
||||
var file = App.RootPath + LogFile;
|
||||
@@ -39,16 +36,30 @@ namespace Ink_Canvas.Helpers
|
||||
{
|
||||
Directory.CreateDirectory(App.RootPath);
|
||||
}
|
||||
StreamWriter sw = new StreamWriter(file, true);
|
||||
sw.WriteLine(string.Format("{0} [{1}] {2}", DateTime.Now.ToString("O"), strLogType, str));
|
||||
sw.Close();
|
||||
var threadId = Thread.CurrentThread.ManagedThreadId;
|
||||
var callingMethod = new StackTrace(2, true).GetFrame(0);
|
||||
string callerInfo = "<unknown>";
|
||||
if (callingMethod != null)
|
||||
{
|
||||
var method = callingMethod.GetMethod();
|
||||
if (method != null)
|
||||
{
|
||||
var className = method.DeclaringType != null ? method.DeclaringType.FullName : "<no class>";
|
||||
callerInfo = $"{className}.{method.Name}";
|
||||
}
|
||||
}
|
||||
string logLine = string.Format("{0} [T{1}] [{2}] [{3}] {4}", DateTime.Now.ToString("O"), threadId, strLogType, callerInfo, str);
|
||||
using (StreamWriter sw = new StreamWriter(file, true))
|
||||
{
|
||||
sw.WriteLine(logLine);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
internal static void WriteLogToFile(string v, object warning)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
WriteLogToFile($"[Warning] {v}", LogType.Warning);
|
||||
}
|
||||
|
||||
public enum LogType
|
||||
|
||||
@@ -106,7 +106,7 @@
|
||||
<Viewbox Margin="0,10">
|
||||
<ui:SymbolIcon Symbol="Globe" Foreground="White"/>
|
||||
</Viewbox>
|
||||
<TextBlock Text="调用外部点名" Foreground="White" FontSize="22" Margin="-1,-1,4,0" VerticalAlignment="Center"/>
|
||||
<TextBlock Text="ClassIsland点名" Foreground="White" FontSize="18" Margin="-1,-1,4,0" VerticalAlignment="Center"/>
|
||||
</ui:SimpleStackPanel>
|
||||
</Border>
|
||||
</ui:SimpleStackPanel>
|
||||
|
||||
@@ -207,8 +207,20 @@ namespace Ink_Canvas {
|
||||
Close();
|
||||
}
|
||||
|
||||
private bool isIslandCallerFirstClick = true;
|
||||
|
||||
private void BorderBtnIslandCaller_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (isIslandCallerFirstClick)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"首次使用ClassIsland点名功能,请确保已安装ClassIsland和Island caller插件。\n" +
|
||||
"如未安装,请前往官网下载并安装后再使用。",
|
||||
"提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
isIslandCallerFirstClick = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
#pragma checksum "..\..\..\..\Windows\RandWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "695B3561F1F2C3284724BFAA9122C85C2EF5221A"
|
||||
#pragma checksum "..\..\..\..\Windows\RandWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "A29F1514A9DC6332F074303F230464CD5C24A898"
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码由工具生成。
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#pragma checksum "..\..\..\..\Windows\RandWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "695B3561F1F2C3284724BFAA9122C85C2EF5221A"
|
||||
#pragma checksum "..\..\..\..\Windows\RandWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "A29F1514A9DC6332F074303F230464CD5C24A898"
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码由工具生成。
|
||||
|
||||
Reference in New Issue
Block a user