nblumhardt / serilog-timings

Extends Serilog with support for timed operations
Apache License 2.0
218 stars 21 forks source link

Operation.Begin throws a System.DivideByZero Exception #49

Closed bfitzgerald80 closed 2 years ago

bfitzgerald80 commented 2 years ago

Looks like a bug was introduced in 3.0 release when Stopwatch.Frequency < TimeSpan.TicksPerSecond. This causes StopwatchToTimeSpanTicks to be 0, which in turn causes Operation.GetTimestamp() to be throw a divide by 0 exception. Specifically

System.DivideByZeroException: Attempted to divide by zero.
   at SerilogTimings.Operation..ctor(ILogger target, String messageTemplate, Object[] args, CompletionBehaviour completionBehaviour, LogEventLevel completionLevel, LogEventLevel abandonmentLevel, Nullable`1 warningThreshold)
   at SerilogTimings.Operation.Begin(String messageTemplate, Object[] args)
Arthur-Neto commented 2 years ago

Got the same error when running some Unit Tests on Azure DevOps pipelines

nblumhardt commented 2 years ago

Fixed in #50

nblumhardt commented 2 years ago

Version 3.0.1-dev-00037 is on NuGet with this change; if anyone has a chance to test and verify that it fixes their issue, I'll queue up a patch release from main. Thanks!