Skip to content

Commit

Permalink
Change to using Splat logging, add ms build task first logic pass
Browse files Browse the repository at this point in the history
  • Loading branch information
glennawatson committed May 15, 2019
1 parent 5e1c577 commit 44846aa
Show file tree
Hide file tree
Showing 13 changed files with 315 additions and 60 deletions.
3 changes: 0 additions & 3 deletions src/Pharmacist.Console/Pharmacist.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

<ItemGroup>
<PackageReference Include="commandlineparser" Version="2.5.0" />
<PackageReference Include="Serilog.Settings.AppSettings" Version="2.2.2" />
<PackageReference Include="serilog.sinks.coloredconsole" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
18 changes: 7 additions & 11 deletions src/Pharmacist.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
using Pharmacist.Core;
using Pharmacist.Core.NuGet;

using Serilog;
using Serilog.Events;
using Splat;

using Parser = CommandLine.Parser;

Expand All @@ -33,18 +32,15 @@ internal static class Program

public static async Task<int> Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.ColoredConsole(LogEventLevel.Information)
.WriteTo.File("EventBuilder.Log")
.CreateLogger();

// allow app to be debugged in visual studio.
if (args.Length == 0 && Debugger.IsAttached)
{
args = "generate-platform --platforms=uwp --output-path=test.txt".Split(' ');
}

var funcLogManager = new FuncLogManager(type => new WrappingFullLogger(new WrappingPrefixLogger(new ConsoleLogger(), type)));
Locator.CurrentMutable.RegisterConstant(funcLogManager, typeof(ILogManager));

var parserResult = new Parser(parserSettings => parserSettings.CaseInsensitiveEnumValues = true)
.ParseArguments<CustomAssembliesCommandLineOptions, PlatformCommandLineOptions>(args);

Expand All @@ -64,7 +60,7 @@ public static async Task<int> Main(string[] args)
}
catch (Exception ex)
{
Log.Fatal(ex.ToString());
LogHost.Default.Fatal(ex);
return ExitCode.Error;
}
},
Expand All @@ -81,7 +77,7 @@ public static async Task<int> Main(string[] args)
}
catch (Exception ex)
{
Log.Fatal(ex.ToString());
LogHost.Default.Fatal(ex);
return ExitCode.Error;
}
},
Expand All @@ -100,7 +96,7 @@ public static async Task<int> Main(string[] args)
}
catch (Exception ex)
{
Log.Fatal(ex.ToString());
LogHost.Default.Fatal(ex);
return ExitCode.Error;
}
},
Expand Down
31 changes: 18 additions & 13 deletions src/Pharmacist.Core/NuGet/NuGetLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,37 @@

using NuGet.Common;

using Splat;

using ILogger = NuGet.Common.ILogger;
using LogLevel = NuGet.Common.LogLevel;

namespace Pharmacist.Core.NuGet
{
/// <summary>
/// A logger provider for the NuGet clients API.
/// </summary>
internal class NuGetLogger : ILogger
internal class NuGetLogger : ILogger, IEnableLogger
{
/// <inheritdoc />
public void Log(LogLevel level, string data)
{
switch (level)
{
case LogLevel.Warning:
Serilog.Log.Warning(data);
this.Log().Warn(data);
break;
case LogLevel.Error:
Serilog.Log.Error(data);
this.Log().Error(data);
break;
case LogLevel.Information:
Serilog.Log.Information(data);
this.Log().Info(data);
break;
case LogLevel.Debug:
Serilog.Log.Debug(data);
this.Log().Debug(data);
break;
default:
Serilog.Log.Verbose(data);
this.Log().Info(data);
break;
}
}
Expand Down Expand Up @@ -60,43 +65,43 @@ public Task LogAsync(ILogMessage message)
/// <inheritdoc />
public void LogDebug(string data)
{
Serilog.Log.Debug(data);
this.Log().Debug(data);
}

/// <inheritdoc />
public void LogError(string data)
{
Serilog.Log.Error(data);
this.Log().Error(data);
}

/// <inheritdoc />
public void LogInformation(string data)
{
Serilog.Log.Information(data);
this.Log().Info(data);
}

/// <inheritdoc />
public void LogInformationSummary(string data)
{
Serilog.Log.Information(data);
this.Log().Info(data);
}

/// <inheritdoc />
public void LogMinimal(string data)
{
Serilog.Log.Information(data);
this.Log().Info(data);
}

/// <inheritdoc />
public void LogVerbose(string data)
{
Serilog.Log.Verbose(data);
this.Log().Info(data);
}

/// <inheritdoc />
public void LogWarning(string data)
{
Serilog.Log.Warning(data);
this.Log().Warn(data);
}
}
}
11 changes: 6 additions & 5 deletions src/Pharmacist.Core/ObservablesForEventGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -22,7 +23,7 @@
using Pharmacist.Core.Reflection;
using Pharmacist.Core.Reflection.Resolvers;

using Serilog;
using Splat;

namespace Pharmacist.Core
{
Expand Down Expand Up @@ -61,7 +62,7 @@ public static async Task ExtractEventsFromPlatforms(string outputPath, string pr
{
foreach (var platform in platforms)
{
Log.Information("Processing platform {0}", platform);
LogHost.Default.Info(CultureInfo.InvariantCulture, "Processing platform {0}", platform);
var platformExtractor = _platformExtractors[platform];
await platformExtractor.Extract(defaultReferenceAssemblyLocation).ConfigureAwait(false);

Expand All @@ -70,7 +71,7 @@ public static async Task ExtractEventsFromPlatforms(string outputPath, string pr
await ExtractEventsFromAssemblies(stream, platformExtractor.Assemblies, platformExtractor.SearchDirectories).ConfigureAwait(false);
}

Log.Information("Finished platform {0}", platform);
LogHost.Default.Info(CultureInfo.InvariantCulture, "Finished platform {0}", platform);
}
}

Expand All @@ -83,14 +84,14 @@ public static async Task ExtractEventsFromPlatforms(string outputPath, string pr
/// <returns>A task to monitor the progress.</returns>
public static async Task ExtractEventsFromNuGetPackages(Stream outputStream, PackageIdentity package, NuGetFramework framework)
{
Log.Information("Processing NuGet package {0}", package);
LogHost.Default.Info(CultureInfo.InvariantCulture, "Processing NuGet package {0}", package);

var extractor = new NuGetExtractor();
await extractor.Extract(framework, package).ConfigureAwait(false);

await ExtractEventsFromAssemblies(outputStream, extractor.Assemblies, extractor.SearchDirectories).ConfigureAwait(false);

Log.Information("Finished NuGet package {0}", package);
LogHost.Default.Info(CultureInfo.InvariantCulture, "Finished NuGet package {0}", package);
}

/// <summary>
Expand Down
6 changes: 2 additions & 4 deletions src/Pharmacist.Core/Pharmacist.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand All @@ -9,13 +9,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ConcurrentHashSet" Version="1.0.2" />
<PackageReference Include="ICSharpCode.Decompiler" Version="4.0.0.4521" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.0.0" />
<PackageReference Include="nuget.protocol" Version="5.0.0" />
<PackageReference Include="polly" Version="7.1.0" />
<PackageReference Include="serilog" Version="2.8.0" />
<PackageReference Include="stubble.core" Version="1.2.7" />
<PackageReference Include="splat" Version="7.2.1" />
<PackageReference Include="system.collections.immutable" Version="1.5.0" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions src/Pharmacist.Core/Reflection/ReflectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.TypeSystem.Implementation;

using Serilog;
using Splat;

namespace Pharmacist.Core.Reflection
{
Expand Down Expand Up @@ -134,15 +134,15 @@ public static IType GetEventType(this IEvent eventDetails)
// Find the EventArgs type parameter of the event via digging around via reflection
if (!eventDetails.CanAdd || !eventDetails.CanRemove)
{
Log.Debug($"Type for {eventDetails.DeclaringType.FullName} is not valid");
LogHost.Default.Debug($"Type for {eventDetails.DeclaringType.FullName} is not valid");
return null;
}

IType type = GetRealType(eventDetails.ReturnType, compilation);

if (type == null)
{
Log.Debug($"Type for {eventDetails.DeclaringType.FullName} is not valid");
LogHost.Default.Debug($"Type for {eventDetails.DeclaringType.FullName} is not valid");
return null;
}

Expand Down
Loading

0 comments on commit 44846aa

Please sign in to comment.