mirror of https://github.com/2dust/v2rayN
Join log4net
parent
716029def8
commit
6a427a2158
|
@ -33,7 +33,7 @@ namespace v2rayN
|
|||
|
||||
if (!IsDuplicateInstance())
|
||||
{
|
||||
|
||||
Logging.Setup();
|
||||
Utils.SaveLog($"v2rayN start up | {Utils.GetVersion()} | {Utils.GetExePath()}");
|
||||
|
||||
//设置语言环境
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
using log4net;
|
||||
using log4net.Appender;
|
||||
using log4net.Core;
|
||||
using log4net.Layout;
|
||||
using log4net.Repository.Hierarchy;
|
||||
|
||||
namespace v2rayN.Tool
|
||||
{
|
||||
public class Logging
|
||||
{
|
||||
public static void Setup()
|
||||
{
|
||||
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
|
||||
|
||||
PatternLayout patternLayout = new PatternLayout();
|
||||
patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
|
||||
patternLayout.ActivateOptions();
|
||||
|
||||
RollingFileAppender roller = new RollingFileAppender();
|
||||
roller.AppendToFile = true;
|
||||
roller.RollingStyle = RollingFileAppender.RollingMode.Date;
|
||||
roller.DatePattern = "yyyy-MM-dd'.txt'";
|
||||
roller.File = Utils.GetPath(@"guiLogs\");
|
||||
roller.Layout = patternLayout;
|
||||
roller.StaticLogFileName = false;
|
||||
roller.ActivateOptions();
|
||||
hierarchy.Root.AddAppender(roller);
|
||||
|
||||
MemoryAppender memory = new MemoryAppender();
|
||||
memory.ActivateOptions();
|
||||
hierarchy.Root.AddAppender(memory);
|
||||
|
||||
hierarchy.Root.Level = Level.Info;
|
||||
hierarchy.Configured = true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@ using System.Security.Principal;
|
|||
using v2rayN.Base;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Web;
|
||||
using log4net;
|
||||
|
||||
namespace v2rayN
|
||||
{
|
||||
|
@ -870,37 +871,14 @@ namespace v2rayN
|
|||
|
||||
public static void SaveLog(string strContent)
|
||||
{
|
||||
SaveLog("info", new Exception(strContent));
|
||||
var logger = LogManager.GetLogger("Log1");
|
||||
logger.Info(strContent);
|
||||
}
|
||||
public static void SaveLog(string strTitle, Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
string path = Path.Combine(StartupPath(), "guiLogs");
|
||||
string FilePath = Path.Combine(path, DateTime.Now.ToString("yyyyMMdd") + ".txt");
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
if (!File.Exists(FilePath))
|
||||
{
|
||||
FileStream FsCreate = new FileStream(FilePath, FileMode.Create);
|
||||
FsCreate.Close();
|
||||
FsCreate.Dispose();
|
||||
}
|
||||
FileStream FsWrite = new FileStream(FilePath, FileMode.Append, FileAccess.Write);
|
||||
StreamWriter SwWrite = new StreamWriter(FsWrite);
|
||||
|
||||
string strContent = ex.ToString();
|
||||
|
||||
SwWrite.WriteLine(string.Format("{0}{1}[{2}]{3}", "--------------------------------", strTitle, DateTime.Now.ToString("HH:mm:ss"), "--------------------------------"));
|
||||
SwWrite.Write(strContent);
|
||||
SwWrite.WriteLine(Environment.NewLine);
|
||||
SwWrite.WriteLine(" ");
|
||||
SwWrite.Flush();
|
||||
SwWrite.Close();
|
||||
}
|
||||
catch { }
|
||||
var logger = LogManager.GetLogger("Log2");
|
||||
logger.Debug(strTitle);
|
||||
logger.Debug(ex);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
Loading…
Reference in New Issue