Skip to content

Commit

Permalink
publish diagnostics message with enabled/disabled status
Browse files Browse the repository at this point in the history
  • Loading branch information
RagingKore committed May 15, 2024
1 parent 533d91e commit 595d85a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/EventStore.Plugins/EventStore.Plugins.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<Platforms>AnyCPU</Platforms>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
26 changes: 10 additions & 16 deletions src/EventStore.Plugins/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,13 @@ IServiceCollection IPlugableComponent.ConfigureServices(IServiceCollection servi
}

IApplicationBuilder IPlugableComponent.Configure(IApplicationBuilder app) {
PublishDiagnostics(new() { ["enabled"] = Enabled });

var logger = app.ApplicationServices.GetRequiredService<ILoggerFactory>().CreateLogger(GetType());

var license = app.ApplicationServices.GetService<License>();

if (Enabled && LicensePublicKey is not null && (license is null || !license.IsValid(LicensePublicKey))) {
if (Enabled && LicensePublicKey is not null && (license is null || !license.IsValid(LicensePublicKey)))
throw new PluginLicenseException(Name);

// logger.LogCritical(
// "A valid license is required but was not found. " +
// "Please obtain a license or disable the plugin."
// );
//
// return app;
}

if (!Enabled) {
logger.LogInformation(
Expand All @@ -118,22 +111,23 @@ IApplicationBuilder IPlugableComponent.Configure(IApplicationBuilder app) {

return app;
}

logger.LogInformation("{Version} plugin enabled.", Version);

ConfigureApplication(app, Configuration);

PublishDiagnostics(new() { ["enabled"] = Enabled });

return app;
}

protected internal void PublishDiagnostics(string eventName, Dictionary<string, object?> eventData) {
// if (DiagnosticListener.IsEnabled(nameof(PluginDiagnosticsData)))
DiagnosticListener.Write(
nameof(PluginDiagnosticsData),
nameof(PluginDiagnosticsData),
new PluginDiagnosticsData(
DiagnosticsName,
eventName,
eventData,
DiagnosticsName,
eventName,
eventData,
DateTimeOffset.UtcNow
)
);
Expand Down

0 comments on commit 595d85a

Please sign in to comment.