Skip to content

Commit

Permalink
Merge pull request #1006 from Particular/plugin-check
Browse files Browse the repository at this point in the history
Improvements in plugin loading and error handling
  • Loading branch information
HEskandari authored Feb 15, 2021
2 parents 71706b6 + 95f4229 commit b4ffb25
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/ServiceInsight.Tests/ShellViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public void TestInitialize()
app,
windowManager,
Substitute.For<IApplicationVersionService>(),
logWindow,
endpointExplorer,
messageList,
() => Substitute.For<ServiceControlConnectionViewModel>(),
Expand All @@ -97,14 +98,13 @@ public void TestInitialize()
licenseManager,
messageFlow,
sagaWindow,
messageBodyView,
headerView,
sequenceDiagramView,
settingsProvider,
versionUpdateChecker,
messageProperties,
logWindow,
commandLineArgParser);
commandLineArgParser,
messageBodyView);

((IViewAware)shell).AttachView(view);
}
Expand Down
2 changes: 0 additions & 2 deletions src/ServiceInsight/AssemblyScanning/AssemblyScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ IEnumerable<string> ReservedAssemblyNames
yield return "DevExpress";
yield return "Serilog";
yield return "Mindscape";
yield return "System";
yield return "Microsoft";
yield return "RestSharp";
yield return "GongSolutions";
yield return "ICSharpCode";
Expand Down
19 changes: 15 additions & 4 deletions src/ServiceInsight/Framework/Logging/LoggingConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
{
using System;
using System.IO;
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using Caliburn.Micro;
using LogWindow;
using MessageViewers.CustomMessageViewer;
using Serilog;
using Serilog.Core;
using Serilog.Events;
using Serilog.Filters;
using ServiceControl;
Expand All @@ -19,9 +22,7 @@ public static void SetupLogging()

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()

// Turn off some of Caliburn.Micro's chattiness
.Filter.ByExcluding(le => Matching.FromSource(typeof(Screen).FullName)(le) && le.Level <= LogEventLevel.Information)
.Filter.ByExcluding(le => Matching.FromSource(typeof(Screen).FullName)(le) && le.Level <= LogEventLevel.Information) // Turn off some of Caliburn.Micro's chattiness
.Filter.ByExcluding(le => Matching.FromSource(typeof(Caliburn.Micro.Action).FullName)(le) && le.Level <= LogEventLevel.Information)
.Filter.ByExcluding(le => Matching.FromSource(typeof(ActionMessage).FullName)(le) && le.Level <= LogEventLevel.Information)
.Filter.ByExcluding(le => Matching.FromSource(typeof(ViewModelBinder).FullName)(le) && le.Level <= LogEventLevel.Information)
Expand All @@ -30,7 +31,7 @@ public static void SetupLogging()
.WriteTo.Trace(outputTemplate: "[{Level}] ({SourceContext}) {Message}{NewLine}{Exception}")
.WriteTo.Logger(lc => lc
.MinimumLevel.Verbose()
.Filter.ByIncludingOnly(Matching.FromSource<DefaultServiceControl>())
.Filter.ByIncludingOnly(MatchingTypes(typeof(DefaultServiceControl), typeof(CustomMessageViewerResolver)))
.WriteTo.Observers(logEvents => logEvents
.ObserveOn(TaskPoolScheduler.Default)
.Do(LogWindowViewModel.LogObserver)
Expand All @@ -42,5 +43,15 @@ public static void SetupCaliburnMicroLogging()
{
LogManager.GetLog = type => new CaliburnMicroLogAdapter(Log.ForContext(type));
}

static Func<LogEvent, bool> MatchingTypes(params Type[] type)
{
var scalars = type.Select(t => new ScalarValue(t.FullName));

return e =>
{
return scalars.Any(s => e.Properties.TryGetValue(Constants.SourceContextPropertyName, out var propertyValue) && s.Equals(propertyValue));
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace ServiceInsight.MessageViewers.CustomMessageViewer
{
using System;
using Anotar.Serilog;
using Autofac;

sealed class CustomMessageViewerResolver : ICustomMessageViewerResolver
Expand All @@ -13,7 +15,22 @@ public CustomMessageViewerResolver(ILifetimeScope autofacContainer)

public ICustomMessageBodyViewer GetCustomMessageBodyViewer()
{
return autofacContainer.ResolveOptional<ICustomMessageBodyViewer>() ?? new NopViewer();
try
{
var viewer = autofacContainer.ResolveOptional<ICustomMessageBodyViewer>();

if (viewer != null)
{
LogTo.Information("Loaded {0} custom message viewer from the plugin.", viewer.GetType());
}

return viewer ?? new NopViewer();
}
catch (Exception ex)
{
LogTo.Fatal(ex, "Failed to load the custom viewer plugin.");
return new NopViewer();
}
}
}
}
8 changes: 1 addition & 7 deletions src/ServiceInsight/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,4 @@

[assembly: ThemeInfo(
ResourceDictionaryLocation.None,
//where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly)]
//where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
ResourceDictionaryLocation.SourceAssembly)]
6 changes: 3 additions & 3 deletions src/ServiceInsight/Shell/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public ShellViewModel(
IAppCommands appCommander,
IWindowManagerEx windowManager,
IApplicationVersionService applicationVersionService,
LogWindowViewModel logWindow,
EndpointExplorerViewModel endpointExplorer,
MessageListViewModel messages,
Func<ServiceControlConnectionViewModel> serviceControlConnection,
Expand All @@ -69,14 +70,13 @@ public ShellViewModel(
AppLicenseManager licenseManager,
MessageFlowViewModel messageFlow,
SagaWindowViewModel sagaWindow,
MessageBodyViewModel messageBodyViewer,
MessageHeadersViewModel messageHeadersViewer,
SequenceDiagramViewModel sequenceDiagramViewer,
ISettingsProvider settingsProvider,
IVersionUpdateChecker versionUpdateChecker,
MessagePropertiesViewModel messageProperties,
LogWindowViewModel logWindow,
CommandLineArgParser commandLineArgParser)
CommandLineArgParser commandLineArgParser,
MessageBodyViewModel messageBodyViewer)
{
this.appCommander = appCommander;
this.windowManager = windowManager;
Expand Down
5 changes: 0 additions & 5 deletions src/ServiceInsight/Startup/CommandLineArgParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
{
using System;
using System.IO.Pipes;
using System.ServiceProcess;
using Serilog;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Sockets;
using Anotar.Serilog;
using ServiceInsight.Models;
using ServiceInsight.Framework.Settings;

public class CommandLineArgParser
{
Expand Down

0 comments on commit b4ffb25

Please sign in to comment.