DEV Community

Discussion on: An Introduction to Graylog

Collapse
 
mtyide profile image
mtyide

Hi,

Quick question: I would like to append additional metadata (information about an object) scoped fields using Gelf.Logging.Extensions, how would I go about this and could I possibly add those fields using custom middle-ware or a custom logger so that you don't have to add those fields at every point where I log?

This is my current implementation:

public async Task HandleAsync(LoginAuditEvent auditEvent)
{
if (auditEvent.TraceData == null) auditEvent.TraceData = new Dictionary();
using (_logger.BeginScope(auditEvent.TraceData))...

Would this be okay or should I change my Dictionary definition to allow for objects to be logged?

Thank you

Collapse
 
klauenboesch profile image
Christian

I'm not an expert on the Java implementation of GELF. I usually use GELF in C# or PHP. However, what I know from other implementations (and from GELF itself) that the format is pretty flexible and can adjust very much to your needs. Depending on the library you use, it might be possible to add some middle-ware that adds the metadate you want dynamically/automatically without the Logger object being aware of.