mirror of
https://github.com/2dust/v2rayN.git
synced 2025-05-03 13:48:52 +00:00
Join log4net
This commit is contained in:
parent
716029def8
commit
6a427a2158
3 changed files with 44 additions and 29 deletions
|
@ -33,7 +33,7 @@ namespace v2rayN
|
||||||
|
|
||||||
if (!IsDuplicateInstance())
|
if (!IsDuplicateInstance())
|
||||||
{
|
{
|
||||||
|
Logging.Setup();
|
||||||
Utils.SaveLog($"v2rayN start up | {Utils.GetVersion()} | {Utils.GetExePath()}");
|
Utils.SaveLog($"v2rayN start up | {Utils.GetVersion()} | {Utils.GetExePath()}");
|
||||||
|
|
||||||
//设置语言环境
|
//设置语言环境
|
||||||
|
|
37
v2rayN/v2rayN/Tool/Logging.cs
Normal file
37
v2rayN/v2rayN/Tool/Logging.cs
Normal file
|
@ -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 v2rayN.Base;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
using log4net;
|
||||||
|
|
||||||
namespace v2rayN
|
namespace v2rayN
|
||||||
{
|
{
|
||||||
|
@ -870,37 +871,14 @@ namespace v2rayN
|
||||||
|
|
||||||
public static void SaveLog(string strContent)
|
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)
|
public static void SaveLog(string strTitle, Exception ex)
|
||||||
{
|
{
|
||||||
try
|
var logger = LogManager.GetLogger("Log2");
|
||||||
{
|
logger.Debug(strTitle);
|
||||||
string path = Path.Combine(StartupPath(), "guiLogs");
|
logger.Debug(ex);
|
||||||
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 { }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
Loading…
Reference in a new issue