JudahGabriel / RavenDB.StructuredLog

An ASP.NET Core logger that utilizes RavenDB to store structured logs.
https://www.nuget.org/packages/RavenDB.StructuredLogger
MIT License
12 stars 6 forks source link

performance check? #2

Closed MohMehrnia closed 4 years ago

MohMehrnia commented 4 years ago

You have checked the group logging performance for a thousand logs?

JudahGabriel commented 4 years ago

Yes, we've used RavenDB.StructuredLog with thousands of logs. Performance is good. In best case, we use direct read from Raven's Voron storage engine. In worst case, we do an index-backed query. Either way, performance is very good.

Moreover, any background work we do, such as writing Raven, is done in the background. Additionally, if logging in done in quick succession, RavenDB.StructuredLog batches the logs together, writing them to Raven in a single batch.

Does this answer your question?

MohMehrnia commented 4 years ago

I mixed Audit.NET and RavenDB.StructuredLog for change capturing, I am worried about the decline in performance for many changes I used below syntaxes for logging:

public override void OnScopeSaving(AuditScope auditScope)
        {
            try
            {
                _logger.LogInformation("Audit event recorded: {event}", new
                {
                    IPAddress = _accessor.HttpContext?.Connection?.RemoteIpAddress?.ToString(),
                    Event = auditScope.Event
                });
            }
            catch (Exception)
            {
                Database.CurrentTransaction.Rollback();
                throw;
            }
            Database.CurrentTransaction.Commit();
        }
    }
JudahGabriel commented 4 years ago

_logger.LogInformation will never throw. That merely puts logging work on the background thread, to be moved in the database at a later time in bulk. So, you don't need try/catch here.

As for performance, again, there's very little overhead; going across the network to the database is the only resource-heavy thing going on. (And even for that, we do batch work; logging many times in quick succession will result in only 1 trip over the network.) If you feel there still are perf issues, try running a performance profiler and see what comes. I'm quite confident RavenDB.StructuredLog will not be the performance culprit.

MohMehrnia commented 4 years ago

I'm sure you're right, I just wanted to make sure, thanks