Skip to content

Commit

Permalink
添加配置文件 jitwxs#51
Browse files Browse the repository at this point in the history
  • Loading branch information
millennium committed Mar 30, 2022
1 parent d8f256e commit c9a1392
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions WindowsFormsApp1/163MusicLyrics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@
<DesignTime>True</DesignTime>
</Compile>
<None Include="GetLrc_TemporaryKey.pfx" />
<None Include="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand Down
2 changes: 2 additions & 0 deletions WindowsFormsApp1/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Net;
using System.Text;
using System.Windows.Forms;
using NLog;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

Expand All @@ -13,6 +14,7 @@ namespace 网易云歌词提取
public partial class MainForm : Form
{
private readonly NetEaseMusicApiWrapper _api;
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();

private readonly Dictionary<long, SaveVo> _globalSaveVoMap = new Dictionary<long, SaveVo>();

Expand Down
44 changes: 44 additions & 0 deletions WindowsFormsApp1/NLog.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8" ?>

<!--<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Trace"
internalLogFile="D:\work\log.txt">-->

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true">

<targets>
<!-- write logs to file -->
<target name="file" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
<target xsi:type="File"
fileName="${basedir}/Logs/${shortdate}.log"
layout="NLog: ${date:format=HH\:mm\:ss} | ${level:uppercase=true:padding=-5} | ${message:exceptionSeparator=\r\n:withException=true}" />
</target>

<target name="debugger" encoding="utf-8"
useDefaultRowHighlightingRules="True"
enableAnsiOutput="False"
xsi:type="Debugger"
layout="NLog: ${date:format=HH\:mm\:ss} | ${level:uppercase=true:padding=-5} | ${message:exceptionSeparator=\r\n:withException=true}" />

<target xsi:type="ColoredConsole" encoding="utf-8" name="console" useDefaultRowHighlightingRules="False"
layout="NLog: ${date:format=HH\:mm\:ss} [${level:uppercase=true}] ${callsite:fileName=False:includeSourcePath=False} ${message}">
<highlight-row condition="level == LogLevel.Debug" foregroundColor="DarkGray" />
<highlight-row condition="level == LogLevel.Info" foregroundColor="Gray" />
<highlight-row condition="level == LogLevel.Warn" foregroundColor="Yellow" />
<highlight-row condition="level == LogLevel.Error" foregroundColor="Red" />
<highlight-row condition="level == LogLevel.Fatal" foregroundColor="Red" backgroundColor="White" />
</target>
</targets>

<rules>
<!--TRACE,DEBUG,INFO,WARN,ERROR,FATAL-->
<!--DEBUG,INFO,WARN,ERROR,FATAL-->
<logger name="*" minlevel="WARN" writeTo="file" />
<!--输出到VS窗口-->
<logger name="*" minlevel="Trace" writeTo="debugger" />
</rules>
</nlog>

0 comments on commit c9a1392

Please sign in to comment.