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

PropertiesColumnWriter: ability to exclude specified properties #21

Open
manisero opened this issue Sep 20, 2018 · 3 comments
Open

PropertiesColumnWriter: ability to exclude specified properties #21

manisero opened this issue Sep 20, 2018 · 3 comments

Comments

@manisero
Copy link

I would like to store LogEvent's properties, but not all of them.
E.g. I store some properties as separate columns using SinglePropertyColumnWriter and I don't want to duplicate them in "properties" column:

var columnWriters = new Dictionary<string, ColumnWriterBase>
{
  ["code"] = new SinglePropertyColumnWriter("LogCode"),
  ["properties"] = new PropertiesColumnWriter(NpgsqlDbType.Jsonb),
  // ...
};

Giving PropertiesColumnWriter an ability exclude specified properties would solve the issue:

var columnWriters = new Dictionary<string, ColumnWriterBase>
{
  ["code"] = new SinglePropertyColumnWriter("LogCode"),
  ["properties"] = new PropertiesColumnWriter(NpgsqlDbType.Jsonb, exclude: new[] { "LogCode" }),
  // ...
};
@nilmas
Copy link

nilmas commented Feb 20, 2019

This ability would be a welcome addition out-of-the-box. I had the same need. Utilized manisero's solution.

@SeppPenner
Copy link

You could use my new project which is basically the same as this repo but will be better maintained: https://github.com/SeppPenner/SerilogSinkForPostgreSQL. Don't hesitate to put this pull request to my repository, too.

@SeppPenner
Copy link

SeppPenner commented May 13, 2019

@nilmas @manisero: What's the benefit of this? I mean, isn't it possible to simply exclude a property from the Dictionary?

From

IDictionary<string, ColumnWriterBase> columnWriters = new Dictionary<string, ColumnWriterBase>
{
    { "message", new RenderedMessageColumnWriter(NpgsqlDbType.Text) },
    { "message_template", new MessageTemplateColumnWriter(NpgsqlDbType.Text) },
    { "level", new LevelColumnWriter(true, NpgsqlDbType.Varchar) },
    { "raise_date", new TimestampColumnWriter(NpgsqlDbType.Timestamp) },
    { "exception", new ExceptionColumnWriter(NpgsqlDbType.Text) }
};

to e.g.:

IDictionary<string, ColumnWriterBase> columnWriters = new Dictionary<string, ColumnWriterBase>
{
    { "message", new RenderedMessageColumnWriter(NpgsqlDbType.Text) },
    { "message_template", new MessageTemplateColumnWriter(NpgsqlDbType.Text) },
    { "raise_date", new TimestampColumnWriter(NpgsqlDbType.Timestamp) },
    { "exception", new ExceptionColumnWriter(NpgsqlDbType.Text) }
};

?

I am planning to bring this feature to my project so you can use it. Check serilog-contrib/Serilog.Sinks.Postgresql.Alternative#8. I will release a new version tomorrow probably.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants