Skip to content

Commit

Permalink
Add logging module
Browse files Browse the repository at this point in the history
  • Loading branch information
fahminlb33 committed Feb 28, 2021
1 parent 4a284fb commit 4d7d9a4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/KFlearning/KFlearning.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,21 @@
<PackageReference Include="Castle.Core">
<Version>4.4.1</Version>
</PackageReference>
<PackageReference Include="Castle.Core-NLog">
<Version>4.4.1</Version>
</PackageReference>
<PackageReference Include="Castle.LoggingFacility">
<Version>5.1.1</Version>
</PackageReference>
<PackageReference Include="Castle.Windsor">
<Version>5.1.1</Version>
</PackageReference>
<PackageReference Include="DotNetZip">
<Version>1.15.0</Version>
</PackageReference>
<PackageReference Include="NLog">
<Version>4.7.8</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KFlearning.Control\KFlearning.Control.csproj">
Expand Down
12 changes: 8 additions & 4 deletions src/KFlearning/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
using System;
using System.Threading;
using System.Windows.Forms;
using Castle.Core.Logging;
using Castle.Windsor;
using KFlearning.Core;
using KFlearning.Core.Extensions;
using KFlearning.Core.Services;
using KFlearning.Properties;
using KFlearning.Services;
using KFlearning.Views;

namespace KFlearning
{
Expand All @@ -43,6 +42,7 @@ static void Main(string[] args)
}

// install services
NLog.GlobalDiagnosticsContext.Set("logDirectory", PathHelpers.GetLogPath());
Container.Install(new KFlearningModulesInstaller());

// find vscode
Expand Down Expand Up @@ -84,9 +84,13 @@ private static void Application_ApplicationExit(object sender, EventArgs e)
usesPersistance.Save();
}
}
catch
catch (Exception ex)
{
// ignore
Container.Resolve<ILogger>().Error("Cannot save persistance", ex);
}
finally
{
NLog.LogManager.Shutdown();
}

Container.Dispose();
Expand Down
3 changes: 3 additions & 0 deletions src/KFlearning/Services/KFlearningModulesInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
using KFlearning.TemplateProvider;
using KFlearning.Views;
using System.Net;
using Castle.Facilities.Logging;
using Castle.Services.Logging.NLogIntegration;

namespace KFlearning.Services
{
public class KFlearningModulesInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.AddFacility<LoggingFacility>(logger => logger.LogUsing<NLogFactory>());
container.Register(
Component.For<WebClient>().ImplementedBy<WebClient>().LifestyleTransient(),

Expand Down
11 changes: 7 additions & 4 deletions src/KFlearning/Services/TelemetryService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using KFlearning.Core.API;
using Castle.Core.Logging;
using KFlearning.Core.API;
using KFlearning.Core.Services;
using System;
using System.Threading.Tasks;
Expand All @@ -13,9 +14,11 @@ public class TelemetryService : ITelemetryService
{
private readonly ISystemInfoService _infoService;
private readonly ITelemetryClient _telemetry;
private readonly ILogger _logger;

public TelemetryService(ITelemetryClient telemetry, ISystemInfoService infoService)
public TelemetryService(ILogger logger, ITelemetryClient telemetry, ISystemInfoService infoService)
{
_logger = logger;
_telemetry = telemetry;
_infoService = infoService;
}
Expand All @@ -42,9 +45,9 @@ public void Load()
})
);
}
catch (Exception)
catch (Exception ex)
{
// ignore
_logger.Error("Cannot post telemetry data", ex);
}
}

Expand Down

0 comments on commit 4d7d9a4

Please sign in to comment.