Skip to content

Commit

Permalink
Added NLog support
Browse files Browse the repository at this point in the history
  • Loading branch information
fahminlb33 committed Feb 28, 2021
1 parent beba058 commit c90af1e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/KFlearning.Core/Extensions/PathHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public static string StripInvalidPathName(string path)
return InvalidFileNameChars.Aggregate(path, (current, x) => current.Replace(x, '_'));
}

public static string GetLogPath()
{
return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
}

public static string GetFullPathToEnv(string fileName)
{
try
Expand Down
8 changes: 8 additions & 0 deletions src/KFlearning.Core/KFlearning.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<None Remove="C:\Users\fahmi\.nuget\packages\nlog.config\4.7.8\contentFiles\any\any\NLog.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
Expand All @@ -36,4 +39,9 @@
<LastGenOutput>AppRes.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
27 changes: 27 additions & 0 deletions src/KFlearning.Core/NLog.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false">

<targets>
<target name="logfile" xsi:type="File" fileName="${gdc:logDirectory:whenEmpty=${specialfolder:folder=LocalApplicationData:cached=true}}/KFlearning/logs/${shortdate}.json" >
<layout xsi:type="JsonLayout">
<attribute name="time" layout="${longdate}" />
<attribute name="level" layout="${level:upperCase=true}"/>
<attribute name="threadId" layout="${threadid}" />
<attribute name="class" layout="${logger}" />
<attribute name="message" layout="${message}" />
<attribute name="eventProperties" encode="false" >
<layout type='JsonLayout' includeAllProperties="true" maxRecursionLimit="2"/>
</attribute>
<attribute name="exception" encode="false" layout="${exception:format=@}" />
</layout>
</target>
</targets>

<rules>
<logger name="*" minlevel="Debug" writeTo="logfile" />
</rules>
</nlog>

0 comments on commit c90af1e

Please sign in to comment.