Skip to content
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

Default fields added by serilog to splunk #62

Closed
sksksksksksk opened this issue Jul 14, 2017 · 5 comments
Closed

Default fields added by serilog to splunk #62

sksksksksksk opened this issue Jul 14, 2017 · 5 comments
Milestone

Comments

@sksksksksksk
Copy link

Is there any way to remove the default fields such as level, template etc. added by serilog while logging data to splunk.

@merbla
Copy link
Contributor

merbla commented Jul 16, 2017

Hi @sksksksksksk,

Some options are available such as turning off template rendering.

renderTemplate: false

Checkout the sample at https://github.com/serilog/serilog-sinks-splunk/blob/dev/sample/Sample/Program.cs#L177

I think the other you mentioned would be new features, they would not be hard to achieve however would stay enabled by default. The easier way to customised the event in Splunk is to extend/override the JSON formatter used. The default uses the package's JSON formatter and could be extended to achieve what you are looking for.

@sksksksksksk
Copy link
Author

sksksksksksk commented Jul 17, 2017

public class SOFormatte : ITextFormatter
{
     new public void Format(LogEvent logEvent, TextWriter output)
    {
        output.Write("{");
        output.Write("hello from serilog");
        output.Write("}\n");
        output.Dispose();
        output.Flush();
    }
}

class Program
{
    public static void Main()
    {
                Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Verbose()
                .WriteTo.EventCollector(
                      myhost,mytoken,
                     jsonFormatter:new SOFormatte(),                    
                    uriPath:"services/collector"
                )
                .WriteTo.Console(new SOFormatte())
                .CreateLogger(); 
                Log.Information(" hello");
                Log.CloseAndFlush();
    }
}

The above code is able to modify console output but is not logging anything to splunk. Why would that be?

@merbla merbla added this to the 2.4 milestone Jul 19, 2017
@merbla
Copy link
Contributor

merbla commented Aug 11, 2017

@sksksksksksk sorry just got back to this one.

I have not had a chance to test your example. It is possible, however that the formatter in the example above is not respecting the payload Splunk is expecting.

There is a SplunkJsonFormatter that is used internally to achieve this.

Details are here.

@Shrutikhurana
Copy link

Ok.. thanks.. It's working now... The format was a little messed up. I corrected it.

@merbla
Copy link
Contributor

merbla commented Aug 13, 2017

👍

@merbla merbla closed this as completed Aug 13, 2017
@merbla merbla mentioned this issue Sep 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants