NickCraver / StackExchange.Exceptional

Error handler used for the Stack Exchange network
https://nickcraver.com/StackExchange.Exceptional/
Apache License 2.0
858 stars 170 forks source link

Settings not loaded from the configuration file when running in a non-web environment #187

Closed robmarsd closed 1 year ago

robmarsd commented 4 years ago

When running in a non web environment (in our case a windows service), the exceptional settings are not loaded from the configuration file.

Given the following configuration:

<configuration>
  <configSections>
      <section name="Exceptional" type="StackExchange.Exceptional.Settings, StackExchange.Exceptional" />
  </configSections>
  <Exceptional applicationName="Some Custom Application Name">
      <ErrorStore type="SQL" connectionString="my connection string" />
  </Exceptional>
</configuration>

When calling:

...
var error = ex.LogNoContext();
var appName = error.Settings.Store.ApplicationName;
var connectionString = error.Settings.Store.ConnectionString;

The value of appName is "My Application" and connectionString is null.

What we need appears to be to call:

StackExchange.Exceptional.Settings.LoadSettings();

But that is inaccessible due to its protection level. As a workaround we can call:

var handlerFactory = new HandlerFactory();

Which internally loads the settings but isn't really ideal in a windows service and means we need the additional StackExchange.Exceptional package reference rather than just StackExchange.Exceptional.Shared.

NickCraver commented 1 year ago

Missed this earlier - this should be resolved in the current version!