Skip to content

Commit

Permalink
更换日志为nlog
Browse files Browse the repository at this point in the history
  • Loading branch information
zc910704 committed Mar 5, 2023
1 parent 352454a commit 8a20cd8
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 27 deletions.
8 changes: 1 addition & 7 deletions SvnSummaryTool/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows;

namespace SvnSummaryTool
{
Expand Down
22 changes: 8 additions & 14 deletions SvnSummaryTool/LogHelper.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
using System;
using Serilog;
using NLog;
using System;

namespace SvnSummaryTool
{
public static class LogHelper
{
private static Logger _Logger = null;
public static void InitLog()
{
Log.Logger = new LoggerConfiguration()
# if DEBUG
.MinimumLevel.Debug()
#else
.MinimumLevel.Information()
#endif
.WriteTo.File(@"logs\log.txt")
.CreateLogger();
_Logger = LogManager.GetCurrentClassLogger();
}

public static void Info(string info) => Serilog.Log.Information(info);
public static void Info(string info) => _Logger.Info(info);

public static void Debug(string info) => Serilog.Log.Debug(info);
public static void Debug(string info) => _Logger.Debug(info);

public static void Error(string msg, Exception e) => Serilog.Log.Error(msg, e);
public static void Error(string msg, Exception e) => _Logger.Error(msg, e);

public static void Close()
{
Serilog.Log.CloseAndFlush();

}
}
}
4 changes: 1 addition & 3 deletions SvnSummaryTool/Model/Log.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Serilog.Core;
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
Expand All @@ -13,7 +12,6 @@ namespace SvnSummaryTool
[XmlRoot(ElementName = "log")]
public class Log
{
public static Logger Logger { get; internal set; }
[XmlElement(ElementName = "logentry")]
public List<Logentry> Logentry { get; set; }

Expand Down
10 changes: 7 additions & 3 deletions SvnSummaryTool/SvnSummaryTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.1.0" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="NLog" Version="5.1.2" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
</ItemGroup>


<ItemGroup>
<None Update="nlog.config" CopyToOutputDirectory="Always" />
</ItemGroup>

<ItemGroup>
<Compile Update="Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
Expand Down
22 changes: 22 additions & 0 deletions SvnSummaryTool/nlog.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- XSD manual extracted from package NLog.Schema: https://www.nuget.org/packages/NLog.Schema-->
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xsi:schemaLocation="NLog NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogFile="%TEMP%\svn-diff-internal.log"
internalLogLevel="Info" >

<!-- the targets to write to -->
<targets>
<!-- write logs to file -->
<target xsi:type="File" name="logfile" fileName="${CurrentDir}\Logs\${shortdate}.log"
layout="${longdate}|${level}|${message} |${all-event-properties} ${exception:format=tostring}" />
<!--<target xsi:type="Console" name="logconsole"
layout="${longdate}|${level}|${message} |${all-event-properties} ${exception:format=tostring}" />-->
</targets>

<!-- rules to map from logger name to target -->
<rules>
<logger name="*" minlevel="Trace" writeTo="logfile,logconsole" />
</rules>
</nlog>

0 comments on commit 8a20cd8

Please sign in to comment.