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

Functions/literals for working with DateTime, DateTimeOffset, and TimeSpan #72

Open
warrenbuckley opened this issue Mar 29, 2022 · 2 comments

Comments

@warrenbuckley
Copy link
Contributor

Hi @nblumhardt 👋
Is it possible that Serilog.Expressions works or already supports working with Timestamp and dates?

Such as some shown in the SEQ Cheatsheet
@Timestamp >= Now() - 1h to get the last log items in the last hour

Or how would you get logs between a specific range of times ?
Look forward to hearing how this could be done or not.

Cheers,
Warren 😄

@nblumhardt
Copy link
Member

Hi @warrenbuckley 👋

Unlike Seq, this library uses DateTime/DateTimeOffset at runtime (instead of 100-nanosecond ticks), so numeric comparisons like >= don't work with these values.

A quick way to enable these today would be to add a Ticks() function:

Ticks(@t) >= Ticks(Now())

The next problem is the 1h, there's no support for this right now but adding an Hours() function would cover it:

Ticks(@t) >= Ticks(Now()) - Ticks(Hours(1))

All a bit clunky, though. I'm not sure whether DateTime comparisons are applicable enough to the core use case of this library to justify all of the implementation challenges we'd hit trying to plug them in, but worth sketching things out 🤔

@warrenbuckley
Copy link
Contributor Author

OK thanks for the pointers 😄
For me consuming the library it has its use case to help with filtering/searching logs when using the raw API but for most users consuming this library to filter out logs by including or excluding with dates probably does not make sense.

I may do a draft PR so we can collaborate to at least discuss ideas and approach by writing my own functions
Then you can decide if it makes sense to include it or not

@nblumhardt nblumhardt changed the title How to work with Timestamp & Dates ? Functions/literals for working with DateTime, DateTimeOffset, and TimeSpan May 10, 2022
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

2 participants