Open nenadvicentic opened 10 months ago
It seems like there is some support. I can tell at least that it will try to ship logs to elastic with default options if you include a Elasticsearch section in the WriteTo array. Is there anyway to tell what is currently supported?
This is the only reason why we're not moving to Elastic.Serilog.Sinks
, so we're waitng for this implementation 🎉
This is really something essential for us too.
fyi I've implemented a workaround: create a custom extension that works with appsettings.json investigating the code on https://github.com/serilog/serilog-settings-configuration I've found a way to implement my own extension method that works with my settings, it requires to:
In my case, the need was just to configure the endpoint address. Since I was coming from serilog-sinks-elasticsearch
package that had a nodeUris
property, I basically just implemented this extension
using Elastic.Serilog.Sinks;
using Serilog.Configuration;
namespace WAY.BuildingBlocks.API;
public static class LoggerConfigurationWayExtensions
{
public static LoggerConfiguration Elasticsearch(this LoggerSinkConfiguration loggerConfiguration, string nodeUris)
=> loggerConfiguration.Elasticsearch(nodes: [new Uri(nodeUris)]);
}
The discovery process of serilog, among other peculiarities, involves the extension be named like the sink (so Elasticsearch in this example) and be implemented in a project whose name contains "Serilog" OR the assembly name be included in the "Using" property under "Serilog" settings ( see https://github.com/serilog/serilog-settings-configuration?tab=readme-ov-file#using-section-and-auto-discovery-of-configuration-assemblies)
Since my project haven't Serilog word in it, I used the "Using" like this
In appsettings I had just to add nodeUris under "Args" property
"WriteTo": [
{
"Name": "Elasticsearch",
"Args": {
"nodeUris": "http://logger-elasticsearch:9200"
}
}
]
and now my extension gets called, that just calls the original extension method accepting an Uri enumeration.
So, while we wait for an official solution, we can create our own extension that fit our needs
My company is also looking to switch to elastic apm and this is a major issue for us as well
@MithrilMan : I've done the same for modifying mongo sink logging before, so I'm not uncomfortable with that solution. Appreciate you taking the time for looking into that and doing a write up 👍
@aj-scram you are welcome, long live the art of making do! :)
I'm trying to migrate lots of projects to Elastic.Serilog.Sinks and am a bit disappointed that out of the box appsettings.json config does not exist yet.
I'm using this config and it works
{ "Name": "Elasticsearch", "Args": { "nodes": [ "http://elasticsearch:9200" ] } }
My company is also looking at migrating many systems to this package and this is a major blocker for us. I wonder how different the two code bases are, perhaps it would not be too much work to bring over that feature from the now deprecated sink.
Serilog
supports full configuration of logging throughappsettings.json
viaSerilog.Settings.Configuration
NuGet package (project is here)For example
Serilog.Sinks.Elasticsearch
supports full configuration viaappsettings.json
. This would be an example:In
Serilog.Sinks.Elasticsearch
this is achieved by exposing extension method for configuration of each of input parameters. Int the code example bellow is simplified extension method, showing only two "Args" parameters used in above JSON configuration file.Full source code of the above extension method can be found here