Skip to content

Commit feb7acd

Browse files
committed
debug:自定义词库保存失败
优化:更新程序添加日志
1 parent 46365d0 commit feb7acd

16 files changed

Lines changed: 343 additions & 37 deletions
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<configSections>
4+
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
5+
</configSections>
6+
<log4net>
7+
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
8+
<file type="log4net.Util.PatternString" value="%property{fname}"/>
9+
<appendToFile value="true" />
10+
<rollingStyle value="Date" />
11+
<datePattern value="_yyyy-MM-dd'.log'" />
12+
<staticLogFileName value="false" />
13+
<param name="MaxSizeRollBackups" value="100" />
14+
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
15+
<layout type="log4net.Layout.PatternLayout">
16+
<conversionPattern value="%-5level %date{HH:mm:ss} 类名:%C 行号:%-4L 信息:【%message】 %n" />
17+
</layout>
18+
</appender>
19+
20+
<appender name="NoClassNoLine" type="log4net.Appender.RollingFileAppender">
21+
<file type="log4net.Util.PatternString" value="%property{fname}"/>
22+
<appendToFile value="true" />
23+
<rollingStyle value="Date" />
24+
<datePattern value="_yyyy-MM-dd'.log'" />
25+
<staticLogFileName value="false" />
26+
<param name="MaxSizeRollBackups" value="100" />
27+
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
28+
<layout type="log4net.Layout.PatternLayout">
29+
<conversionPattern value="%-5level %date{HH:mm:ss} %message %n" />
30+
</layout>
31+
</appender>
32+
33+
<logger name="ZuanBot">
34+
<level value="All" />
35+
<appender-ref ref="RollingLogFileAppender" />
36+
</logger>
37+
38+
<logger name="NoClassNoLine">
39+
<level value="All" />
40+
<appender-ref ref="NoClassNoLine" />
41+
</logger>
42+
43+
</log4net>
44+
<startup>
45+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
46+
</startup>
47+
</configuration>

ZuAnBotUpdate/FodyWeavers.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
2+
<Costura />
3+
</Weavers>

ZuAnBotUpdate/FodyWeavers.xsd

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
4+
<xs:element name="Weavers">
5+
<xs:complexType>
6+
<xs:all>
7+
<xs:element name="Costura" minOccurs="0" maxOccurs="1">
8+
<xs:complexType>
9+
<xs:all>
10+
<xs:element minOccurs="0" maxOccurs="1" name="ExcludeAssemblies" type="xs:string">
11+
<xs:annotation>
12+
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks</xs:documentation>
13+
</xs:annotation>
14+
</xs:element>
15+
<xs:element minOccurs="0" maxOccurs="1" name="IncludeAssemblies" type="xs:string">
16+
<xs:annotation>
17+
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
18+
</xs:annotation>
19+
</xs:element>
20+
<xs:element minOccurs="0" maxOccurs="1" name="ExcludeRuntimeAssemblies" type="xs:string">
21+
<xs:annotation>
22+
<xs:documentation>A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks</xs:documentation>
23+
</xs:annotation>
24+
</xs:element>
25+
<xs:element minOccurs="0" maxOccurs="1" name="IncludeRuntimeAssemblies" type="xs:string">
26+
<xs:annotation>
27+
<xs:documentation>A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
28+
</xs:annotation>
29+
</xs:element>
30+
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged32Assemblies" type="xs:string">
31+
<xs:annotation>
32+
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with line breaks.</xs:documentation>
33+
</xs:annotation>
34+
</xs:element>
35+
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged64Assemblies" type="xs:string">
36+
<xs:annotation>
37+
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with line breaks.</xs:documentation>
38+
</xs:annotation>
39+
</xs:element>
40+
<xs:element minOccurs="0" maxOccurs="1" name="PreloadOrder" type="xs:string">
41+
<xs:annotation>
42+
<xs:documentation>The order of preloaded assemblies, delimited with line breaks.</xs:documentation>
43+
</xs:annotation>
44+
</xs:element>
45+
</xs:all>
46+
<xs:attribute name="CreateTemporaryAssemblies" type="xs:boolean">
47+
<xs:annotation>
48+
<xs:documentation>This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file.</xs:documentation>
49+
</xs:annotation>
50+
</xs:attribute>
51+
<xs:attribute name="IncludeDebugSymbols" type="xs:boolean">
52+
<xs:annotation>
53+
<xs:documentation>Controls if .pdbs for reference assemblies are also embedded.</xs:documentation>
54+
</xs:annotation>
55+
</xs:attribute>
56+
<xs:attribute name="IncludeRuntimeReferences" type="xs:boolean">
57+
<xs:annotation>
58+
<xs:documentation>Controls if runtime assemblies are also embedded.</xs:documentation>
59+
</xs:annotation>
60+
</xs:attribute>
61+
<xs:attribute name="UseRuntimeReferencePaths" type="xs:boolean">
62+
<xs:annotation>
63+
<xs:documentation>Controls whether the runtime assemblies are embedded with their full path or only with their assembly name.</xs:documentation>
64+
</xs:annotation>
65+
</xs:attribute>
66+
<xs:attribute name="DisableCompression" type="xs:boolean">
67+
<xs:annotation>
68+
<xs:documentation>Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option.</xs:documentation>
69+
</xs:annotation>
70+
</xs:attribute>
71+
<xs:attribute name="DisableCleanup" type="xs:boolean">
72+
<xs:annotation>
73+
<xs:documentation>As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off.</xs:documentation>
74+
</xs:annotation>
75+
</xs:attribute>
76+
<xs:attribute name="LoadAtModuleInit" type="xs:boolean">
77+
<xs:annotation>
78+
<xs:documentation>Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code.</xs:documentation>
79+
</xs:annotation>
80+
</xs:attribute>
81+
<xs:attribute name="IgnoreSatelliteAssemblies" type="xs:boolean">
82+
<xs:annotation>
83+
<xs:documentation>Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior.</xs:documentation>
84+
</xs:annotation>
85+
</xs:attribute>
86+
<xs:attribute name="ExcludeAssemblies" type="xs:string">
87+
<xs:annotation>
88+
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation>
89+
</xs:annotation>
90+
</xs:attribute>
91+
<xs:attribute name="IncludeAssemblies" type="xs:string">
92+
<xs:annotation>
93+
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
94+
</xs:annotation>
95+
</xs:attribute>
96+
<xs:attribute name="ExcludeRuntimeAssemblies" type="xs:string">
97+
<xs:annotation>
98+
<xs:documentation>A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation>
99+
</xs:annotation>
100+
</xs:attribute>
101+
<xs:attribute name="IncludeRuntimeAssemblies" type="xs:string">
102+
<xs:annotation>
103+
<xs:documentation>A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
104+
</xs:annotation>
105+
</xs:attribute>
106+
<xs:attribute name="Unmanaged32Assemblies" type="xs:string">
107+
<xs:annotation>
108+
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with |.</xs:documentation>
109+
</xs:annotation>
110+
</xs:attribute>
111+
<xs:attribute name="Unmanaged64Assemblies" type="xs:string">
112+
<xs:annotation>
113+
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with |.</xs:documentation>
114+
</xs:annotation>
115+
</xs:attribute>
116+
<xs:attribute name="PreloadOrder" type="xs:string">
117+
<xs:annotation>
118+
<xs:documentation>The order of preloaded assemblies, delimited with |.</xs:documentation>
119+
</xs:annotation>
120+
</xs:attribute>
121+
</xs:complexType>
122+
</xs:element>
123+
</xs:all>
124+
<xs:attribute name="VerifyAssembly" type="xs:boolean">
125+
<xs:annotation>
126+
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
127+
</xs:annotation>
128+
</xs:attribute>
129+
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
130+
<xs:annotation>
131+
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
132+
</xs:annotation>
133+
</xs:attribute>
134+
<xs:attribute name="GenerateXsd" type="xs:boolean">
135+
<xs:annotation>
136+
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
137+
</xs:annotation>
138+
</xs:attribute>
139+
</xs:complexType>
140+
</xs:element>
141+
</xs:schema>

ZuAnBotUpdate/LogHelper.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using log4net;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Windows;
9+
10+
11+
namespace ZuAnBotUpdate
12+
{
13+
public class LogHelper
14+
{
15+
private ILog _logger = null;
16+
public static string logPath;
17+
18+
public LogHelper(string logDirName = null, string loggerName = "ZuanBot")
19+
{
20+
if (logDirName == null)
21+
InitLogger("ZuanBot", loggerName);
22+
else
23+
{
24+
InitLogger(logDirName, loggerName);
25+
}
26+
}
27+
28+
public ILog Logger4
29+
{
30+
get { return _logger; }
31+
}
32+
33+
/// <summary>
34+
/// 日志将放入%temp%/CECommonLog文件夹
35+
/// </summary>
36+
/// <param name="logDirName"></param>
37+
private void InitLogger(string logDirName, string loggerName)
38+
{
39+
logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "TEMP", logDirName);
40+
if (!Directory.Exists(logPath)) Directory.CreateDirectory(logPath);
41+
log4net.GlobalContext.Properties["fname"] = Path.Combine(logPath, "log");//日志存放位置
42+
43+
var stream = ManifestHelper.GetManifestStream("log4net.config");
44+
log4net.Config.XmlConfigurator.Configure(stream);
45+
stream.Close();
46+
//创建一个实例,名字可随便取
47+
_logger = LogManager.GetLogger(loggerName);
48+
_logger.Info("==================初始化Logger====================");
49+
}
50+
51+
}
52+
}
53+
54+

ZuAnBotUpdate/ManifestHelper.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Reflection;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace ZuAnBotUpdate
10+
{
11+
/// <summary>
12+
/// 清单资源工具类
13+
/// </summary>
14+
public static class ManifestHelper
15+
{
16+
public static Stream GetManifestStream(string jsonName)
17+
{
18+
return Assembly.GetExecutingAssembly().GetManifestResourceStream($"ZuAnBotUpdate.Assets.{jsonName}");
19+
}
20+
}
21+
}

ZuAnBotUpdate/Program.cs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,33 @@ public class Program
99
{
1010
static void Main(string[] args)
1111
{
12-
Console.WriteLine("args.Length:" + args.Length);
13-
if (args.Length != 2) return;
12+
var logger = new LogHelper().Logger4;
13+
try
14+
{
15+
logger.Info("进入更新程序args:" + args.Aggregate((a, b) => a + " " + b));
16+
if (args.Length != 2) return;
1417

15-
var path1 = args[0];
16-
var path2 = args[1];
18+
var path1 = args[0];
19+
var path2 = args[1];
1720

18-
Console.WriteLine("path1:" + path1);
19-
Console.WriteLine("path2:" + path2);
20-
if (string.IsNullOrWhiteSpace(path1) || string.IsNullOrWhiteSpace(path2)) return;
21+
if (string.IsNullOrWhiteSpace(path1) || string.IsNullOrWhiteSpace(path2)) return;
2122

22-
var process = Process.GetProcessesByName("祖安助手").FirstOrDefault();
23+
var process = Process.GetProcessesByName("祖安助手").FirstOrDefault();
2324

24-
if (process == null || process.MainModule?.FileName != path2) return;
25+
if (process == null || process.MainModule?.FileName != path2) return;
2526

26-
process.Kill();
27-
process.WaitForExit(1000);
28-
File.Copy(path1, path2, true);
27+
process.Kill();
28+
process.WaitForExit(1000);
29+
File.Copy(path1, path2, true);
2930

30-
Process.Start(path2);
31+
Process.Start(path2);
3132

32-
Console.WriteLine("成功");
33+
logger.Info("更新程序执行成功");
34+
}
35+
catch (Exception e)
36+
{
37+
logger.Error("更新程序执行出错", e);
38+
}
3339
}
3440
}
3541
}

ZuAnBotUpdate/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"ZuAnBotUpdate": {
44
"commandName": "Project",
5-
"commandLineArgs": "C:\\Users\\Admin\\AppData\\Local\\Temp\\祖安助手.exe F:\\work\\LOL\\ZuAnBot\\ZuAnBot_Wpf\\bin\\Debug\\net472\\祖安助手.exe"
5+
"commandLineArgs": "C:\\Users\\Admin\\AppData\\Local\\Temp\\祖安助手.exe F:\\work\\LOL\\ZuAnBot\\ZuAnBot_Wpf\\bin\\Release\\net472\\祖安助手.exe"
66
}
77
}
88
}

ZuAnBotUpdate/ZuAnBotUpdate.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,16 @@
55
<TargetFramework>net472</TargetFramework>
66
</PropertyGroup>
77

8+
<ItemGroup>
9+
<None Remove="Assets\log4net.config" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<EmbeddedResource Include="Assets\log4net.config" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="log4net" Version="2.0.12" />
18+
</ItemGroup>
19+
820
</Project>

ZuAnBot_Wpf/Assets/log4net.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
</layout>
3131
</appender>
3232

33-
<logger name="liuke">
33+
<logger name="ZuanBot">
3434
<level value="All" />
3535
<appender-ref ref="RollingLogFileAppender" />
3636
</logger>
3737

38-
<logger name="CEBIM">
38+
<logger name="NoClassNoLine">
3939
<level value="All" />
4040
<appender-ref ref="NoClassNoLine" />
4141
</logger>

ZuAnBot_Wpf/Helper/ExceptionExtension.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public static void Show(this Exception e, string msg = "", bool showDetail = tru
7070
else
7171
msg += e.Message;
7272

73+
new LogHelper().Logger4.Error(msg);
74+
7375
MessageHelper.Error(msg);
7476
}
7577
}

0 commit comments

Comments
 (0)