-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d538cbc
commit 15c2b5b
Showing
3 changed files
with
151 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7</TargetFramework> | ||
<StartupObject>ConsoleAppDemo.Program</StartupObject> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7</TargetFramework> | ||
<StartupObject>ConsoleAppDemo.Program</StartupObject> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)'=='Release'"> | ||
<DebugType>none</DebugType> | ||
<DebugSymbols>false</DebugSymbols> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\PollinationSDK\PollinationSDK.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\PollinationSDK\PollinationSDK.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using Serilog; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ConsoleAppDemo | ||
{ | ||
public static class LogHelper | ||
{ | ||
private static string logFolderName = "logs"; | ||
public static Serilog.Core.Logger Log { get; private set; } | ||
//public static Serilog.Log Log = Serilog.Log; | ||
/// <summary> | ||
/// Setup Log.Logger | ||
/// </summary> | ||
/// <param name="logFileName">rename log file name, otherwise it uses log.txt</param> | ||
public static void SetupLogger(string logFileName = default) | ||
{ | ||
var file = string.IsNullOrEmpty(logFileName) ? "log.txt" : logFileName; | ||
var logPath = Path.Combine(LogFolder, file); | ||
Log = new LoggerConfiguration(). | ||
WriteTo.File( | ||
logPath, | ||
rollingInterval: RollingInterval.Hour, | ||
rollOnFileSizeLimit: true, | ||
retainedFileCountLimit: 3 | ||
).CreateLogger(); | ||
Serilog.Log.Logger = Log; | ||
|
||
//Log.Information($"Rhino: {Rhino.RhinoApp.ExeVersion}.{Rhino.RhinoApp.ExeServiceRelease} ({Rhino.RhinoApp.BuildDate})"); | ||
//Log.Information(Utility.GetAboutInfo()); | ||
} | ||
|
||
public static string LogFolder | ||
{ | ||
get | ||
{ | ||
var userAppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); | ||
var podir = Path.Combine(userAppData, "pollination"); | ||
if (!Directory.Exists(podir)) | ||
Directory.CreateDirectory(podir); | ||
|
||
podir = Path.Combine(podir, logFolderName); | ||
if (!Directory.Exists(podir)) | ||
Directory.CreateDirectory(podir); | ||
return podir; | ||
} | ||
} | ||
|
||
public static string GetTheLatestLog() | ||
{ | ||
var folder = new DirectoryInfo(LogFolder); | ||
if (!folder.Exists) return null; | ||
|
||
var lastLog = folder.GetFiles().OrderBy(_ => _.LastWriteTime).LastOrDefault(); | ||
if (lastLog.Exists) return lastLog.FullName; | ||
else return null; | ||
|
||
} | ||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters