Serilog controlling output format for file sink











up vote
0
down vote

favorite












So let me just give a bit of context here we use Serilog and we use various sinks including some of our own ones.



For most of the sinks we add extra properties that we need to use to drive logic, such as routing/filtering etc etc



So for us a given log statement may look something like this



public class SomeClass
{
public String Name { get; set; }
public string AppType { get; set; }
}

var loggingEnvironment = new SomeClass()
{
Name = "foo",
AppType = "test",

};

Logger.Error("{Category} {Message} {@LoggingEnvironment}", LogCategory.BUS, "Oh no its gone bad jim", loggingEnvironment);


Where we need the LoggingEnvironment property to travel all the way through MOST of our sinks.



However for the file Sink output we see if this



2018-11-21 10:30:21.332 [ERR] BUS "Oh no its gone bad jim" SomeClass { Name: "foo", AppType: "test" } 


What we would like the file written text to be its just



2018-11-21 10:30:21.332 [ERR] BUS "Oh no its gone bad jim"


Reading more into this section from Serilog https://github.com/serilog/serilog/wiki/Formatting-Output it talks about the formatters for Message.




Message - The log event's message, rendered as plain text. The :l format specifier switches of quoting of strings, and :j uses JSON-style rendering for any embedded structured data.




But as this extra property is not really part of the message, I don't think that section of the docs applies.



Short of bringing in all the code for the Serilog.Sinks.File into our own codebase, is there a way to get to rid of this (or any other property) value from being written to a sink output?










share|improve this question






















  • So apparently an enricher property is the way to do this stackoverflow.com/questions/30637416/… which will be a property but not in the main message template
    – sacha
    2 days ago

















up vote
0
down vote

favorite












So let me just give a bit of context here we use Serilog and we use various sinks including some of our own ones.



For most of the sinks we add extra properties that we need to use to drive logic, such as routing/filtering etc etc



So for us a given log statement may look something like this



public class SomeClass
{
public String Name { get; set; }
public string AppType { get; set; }
}

var loggingEnvironment = new SomeClass()
{
Name = "foo",
AppType = "test",

};

Logger.Error("{Category} {Message} {@LoggingEnvironment}", LogCategory.BUS, "Oh no its gone bad jim", loggingEnvironment);


Where we need the LoggingEnvironment property to travel all the way through MOST of our sinks.



However for the file Sink output we see if this



2018-11-21 10:30:21.332 [ERR] BUS "Oh no its gone bad jim" SomeClass { Name: "foo", AppType: "test" } 


What we would like the file written text to be its just



2018-11-21 10:30:21.332 [ERR] BUS "Oh no its gone bad jim"


Reading more into this section from Serilog https://github.com/serilog/serilog/wiki/Formatting-Output it talks about the formatters for Message.




Message - The log event's message, rendered as plain text. The :l format specifier switches of quoting of strings, and :j uses JSON-style rendering for any embedded structured data.




But as this extra property is not really part of the message, I don't think that section of the docs applies.



Short of bringing in all the code for the Serilog.Sinks.File into our own codebase, is there a way to get to rid of this (or any other property) value from being written to a sink output?










share|improve this question






















  • So apparently an enricher property is the way to do this stackoverflow.com/questions/30637416/… which will be a property but not in the main message template
    – sacha
    2 days ago















up vote
0
down vote

favorite









up vote
0
down vote

favorite











So let me just give a bit of context here we use Serilog and we use various sinks including some of our own ones.



For most of the sinks we add extra properties that we need to use to drive logic, such as routing/filtering etc etc



So for us a given log statement may look something like this



public class SomeClass
{
public String Name { get; set; }
public string AppType { get; set; }
}

var loggingEnvironment = new SomeClass()
{
Name = "foo",
AppType = "test",

};

Logger.Error("{Category} {Message} {@LoggingEnvironment}", LogCategory.BUS, "Oh no its gone bad jim", loggingEnvironment);


Where we need the LoggingEnvironment property to travel all the way through MOST of our sinks.



However for the file Sink output we see if this



2018-11-21 10:30:21.332 [ERR] BUS "Oh no its gone bad jim" SomeClass { Name: "foo", AppType: "test" } 


What we would like the file written text to be its just



2018-11-21 10:30:21.332 [ERR] BUS "Oh no its gone bad jim"


Reading more into this section from Serilog https://github.com/serilog/serilog/wiki/Formatting-Output it talks about the formatters for Message.




Message - The log event's message, rendered as plain text. The :l format specifier switches of quoting of strings, and :j uses JSON-style rendering for any embedded structured data.




But as this extra property is not really part of the message, I don't think that section of the docs applies.



Short of bringing in all the code for the Serilog.Sinks.File into our own codebase, is there a way to get to rid of this (or any other property) value from being written to a sink output?










share|improve this question













So let me just give a bit of context here we use Serilog and we use various sinks including some of our own ones.



For most of the sinks we add extra properties that we need to use to drive logic, such as routing/filtering etc etc



So for us a given log statement may look something like this



public class SomeClass
{
public String Name { get; set; }
public string AppType { get; set; }
}

var loggingEnvironment = new SomeClass()
{
Name = "foo",
AppType = "test",

};

Logger.Error("{Category} {Message} {@LoggingEnvironment}", LogCategory.BUS, "Oh no its gone bad jim", loggingEnvironment);


Where we need the LoggingEnvironment property to travel all the way through MOST of our sinks.



However for the file Sink output we see if this



2018-11-21 10:30:21.332 [ERR] BUS "Oh no its gone bad jim" SomeClass { Name: "foo", AppType: "test" } 


What we would like the file written text to be its just



2018-11-21 10:30:21.332 [ERR] BUS "Oh no its gone bad jim"


Reading more into this section from Serilog https://github.com/serilog/serilog/wiki/Formatting-Output it talks about the formatters for Message.




Message - The log event's message, rendered as plain text. The :l format specifier switches of quoting of strings, and :j uses JSON-style rendering for any embedded structured data.




But as this extra property is not really part of the message, I don't think that section of the docs applies.



Short of bringing in all the code for the Serilog.Sinks.File into our own codebase, is there a way to get to rid of this (or any other property) value from being written to a sink output?







serilog






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









sacha

953918




953918












  • So apparently an enricher property is the way to do this stackoverflow.com/questions/30637416/… which will be a property but not in the main message template
    – sacha
    2 days ago




















  • So apparently an enricher property is the way to do this stackoverflow.com/questions/30637416/… which will be a property but not in the main message template
    – sacha
    2 days ago


















So apparently an enricher property is the way to do this stackoverflow.com/questions/30637416/… which will be a property but not in the main message template
– sacha
2 days ago






So apparently an enricher property is the way to do this stackoverflow.com/questions/30637416/… which will be a property but not in the main message template
– sacha
2 days ago



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410176%2fserilog-controlling-output-format-for-file-sink%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410176%2fserilog-controlling-output-format-for-file-sink%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)