Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure that single-file apps can find assemblies that contains sinks
Before this commit, when single-file app was detected, the behaviour was to fallback on DLL scanning. But DLL scanning would not find anything for an app published as a single-file, by sheer definition of single-file app! After this commit, an exception is thrown if the app is published as a single-file AND no `Serilog:Using` section is defined in the configuration. The error message explains that either a `Serilog:Using` section must be added or show how to explicitly configure assemblies through the `ConfigurationReaderOptions`.
- Loading branch information
Showing
5 changed files
with
77 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/Serilog.Settings.Configuration/Settings/Configuration/Assemblies/AutoAssemblyFinder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Reflection; | ||
|
||
namespace Serilog.Settings.Configuration.Assemblies; | ||
|
||
class AutoAssemblyFinder : AssemblyFinder | ||
{ | ||
readonly AssemblyFinder[] _assemblyFinders; | ||
|
||
public AutoAssemblyFinder(params AssemblyFinder[] assemblyFinders) | ||
{ | ||
_assemblyFinders = assemblyFinders; | ||
} | ||
|
||
public override bool CanFindAssemblies => _assemblyFinders.Any(e => e.CanFindAssemblies); | ||
|
||
public override IReadOnlyList<AssemblyName> FindAssembliesContainingName(string nameToFind) | ||
{ | ||
var assemblyNames = new List<AssemblyName>(); | ||
foreach (var assemblyFinder in _assemblyFinders) | ||
{ | ||
assemblyNames.AddRange(assemblyFinder.FindAssembliesContainingName(nameToFind)); | ||
} | ||
return assemblyNames; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters