Reputation: 9827
Goal: A single executable, trimmed (size matters for this use case), that at runtime is able to load the Console sink (works) and/or the EventLog sink (fails, my problem here).
Basic .csproj parts:
<PublishSingleFile>true</PublishSingleFile>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishTrimmed>true</PublishTrimmed>
This still fails after trimming without a custom trimming configuration
Add to .csproj
<ItemGroup>
<TrimmerRootDescriptor Include="TrimmerRoots.xml" />
</ItemGroup>
The TrimmerRoots.xml
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<assembly fullname="Serilog" />
<assembly fullname="Serilog.Settings.Configuration" />
<assembly fullname="Serilog.Sinks.Console" />
<assembly fullname="Serilog.Sinks.EventLog" />
</linker>
At this point we're sooooo close. Unfortunately, while logging to the Console from the bundle works now, using say this appsettings.json
{
"Serilog": {
"Using": [ "Serilog", "Serilog.Sinks.Console", "Serilog.Settings.Configuration" ],
"MinimumLevel": "Debug",
"WriteTo": [
{ "Name": "Console" }
],
"Enrich": [ "FromLogContext" ]
}
}
logging to the EventLog silently fails using this appsettings.json
{
"Serilog": {
"Using": [ "Serilog", "Serilog.Sinks.EventLog", "Serilog.Settings.Configuration" ],
"MinimumLevel": {
"Default": "Debug"
},
"WriteTo": [
{
"Name": "EventLog",
"Args": {
"source": "Agent Updater",
"logName": "Application",
"manageEventSource": true
}
}
],
"Enrich": [ "FromLogContext" ]
}
}
If I enable SeriLog self-logging using Serilog.Debugging.SelfLog.Enable(Console.Error);
I get the following message:
2024-01-10T22:55:17.8478998Z Unable to find a method called EventLog for supplied arguments: logName, manageEventSource, source. Candidate methods are:
EventLog(, , , , , , , )
EventLog(, , , , , , )
Logging works perfectly fine in the debugger/before bundling and trimming this project. Any suggestions what is going wrong here at this point?
Upvotes: 1
Views: 113