Does Write-PSULog \ Serilog write to DB asynchronously behind the scene?

That’s my question, when using Write-PSULog to write a log to the DB, does it write using async or sync?

If it isn’t using the Serilog async option, can it be added as a configuration option so it can write async? I would like to replace a home grown logger with Write-PSULog but for performance we need it to write asynchronously to the DB (SQL Server). We produce a huge amount of logs (parallel in many threads) and synchronous writes wouldn’t work in our case. Before I start down the road of retrofitting to test performance figured I should ask first.

Thanks!

Product: PowerShell Universal
Version: 4.1.5
1 Like

Write-PSULog uses await\async communication itself and then the Serilog sync batches log messages and writes them asynchronously.

So it’s async all the way down.

Fantastic, Thank you!

@adam One more question related to logging… Are we able to specify a custom table location for logging or are we locked to LogEntry inside of the PSU database (in SQL Server)? We use an AG and keep the logging database out of it as to not impact performance. We need to keep PSU in the AG though, so being able to write to another table would be huge. Thanks!

@adam And another question :slight_smile: Can we provide custom columns? If not, is that technically feasible, can it be a feature request?

You can specify an alternate database by providing a connection string.

New-PSULoggingTarget -Type Database -Properties @{
      ConnectionString = "ConnectionStringHere" 
}

That said, there currently isn’t a way to specify a different table name or custom columns. It is feasible to add both of those. Serilog has customization for both those items and we would just need to expose them through the target properties.

That did the trick, thank you!

After playing with it I found you have to create the table first before it will write to it. I didn’t see any errors anywhere, even with the logging configuration saved with no errors, it continued to write to the original table\database until I created the table in the new database. Simple, just not clear through the documentation.

I’ll get a request on the issues board for custom columns and a custom table name. Thanks again!