-
Notifications
You must be signed in to change notification settings - Fork 72
No custom logs when using Serilog #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is a limitation in the Serilog logger factory implementation; in particular, Serilog currently ignores added providers and assumes that Serilog Sinks will replace them instead. Some work is underway to alleviate this with: serilog/serilog-extensions-logging#132 - any and all input/assistance appreciated. (Another, probably quicker short-term option might be to implement a simple |
@nblumhardt Thank you very much for response. It would be great to have some solution for now. Could you please suggest how to implement |
Hi @Marusyk
This would need to implement Serilog's There are quite a lot of implementations of The trick will be how to get an Hope this helps! |
Thanks a lot. It was very helpful. My implementations of that: public class OpenTracingSink : ILogEventSink
{
private readonly ITracer _tracer;
private readonly IFormatProvider _formatProvider;
public OpenTracingSink(ITracer tracer, IFormatProvider formatProvider)
{
_tracer = tracer;
_formatProvider = formatProvider;
}
public void Emit(LogEvent logEvent)
{
ISpan span = _tracer.ActiveSpan;
if (span == null)
{
// Creating a new span for a log message seems brutal so we ignore messages if we can't attach it to an active span.
return;
}
var fields = new Dictionary<string, object>
{
{ "component", logEvent.Properties["SourceContext"] },
{ "level", logEvent.Level.ToString() }
};
fields[LogFields.Event] = "log";
try
{
fields[LogFields.Message] = logEvent.RenderMessage(_formatProvider);
fields["message.template"] = logEvent.MessageTemplate.Text;
if (logEvent.Exception != null)
{
fields[LogFields.ErrorKind] = logEvent.Exception.GetType().FullName;
fields[LogFields.ErrorObject] = logEvent.Exception;
}
if (logEvent.Properties != null)
{
foreach (var property in logEvent.Properties)
{
fields[property.Key] = property.Value;
}
}
}
catch (Exception logException)
{
fields["mbv.common.logging.error"] = logException.ToString();
}
span.Log(fields);
}
}
public static class OpenTracingSinkExtensions
{
public static LoggerConfiguration OpenTracing(
this LoggerSinkConfiguration loggerConfiguration,
IFormatProvider formatProvider = null)
{
return loggerConfiguration.Sink(new OpenTracingSink(GlobalTracer.Instance, formatProvider));
}
} After merge your PR, should it work without this sink? |
Fantastic, thanks for the update @Marusyk After we have the new functionality merged, there will need to be some downstream changes before this will be picked up, but ideally - yes, the goal is to not require this. |
Uh oh!
There was an error while loading. Please reload this page.
Requirement - what kind of business use case are you trying to solve?
I need to send to Jaeger custom logs. Now it works only when I use
Microsoft.Extensions.Logging.ILoggerFactory
My Startup
Somewhere in controller:
using Microsoft.Extensions.Logging;
Result

Problem - what in Jaeger blocks you from solving the requirement?
But when I use Serilog, there are no any custom logs. I just install serilog and add
Could you please suggest why custom logging doesn't work with Serilog?
The text was updated successfully, but these errors were encountered: