For test, I removed all my SeriLog configurations, and just left the above ConsoleLogFactory in my code. Still only the SELECT statements are there; I have an insert and and update that does not show in the Debug.
To be clear, I am using this in an asp.net core service host.
When I execute the .Update statement, it will come into OrmLiteWriteCommandExtensions class.
Then I look at the Log, then the type is SerilogLogger. IsDebugEnabled is true.
This is for the statement internal static int Update<T>(this IDbCommand dbCmd, T obj, Action<IDbCommand> commandFilter = null)
In this statement, var rowsUpdated = dbCmd.ExecNonQuery(); is executed. This goes to OrmLiteResultsFilterExtensions class. There the Log field is of type NetCoreLog with IsDebugEnabled is false.
That’s why the Log.DebugCommand(dbCmd); is not executed.
The static initializer is being run before your Logging is configured, so you’ll need to configure it earlier. But are you configuring your logging with ServiceStack’s logging providers instead of .NET Core’s logging abstraction? For .NET Core it’s recommended to use .NET Core’s logging abstraction.
It is a result of trial and error. If I remove the assignment of Serilog as factory evrything logs fine but not the Update… the debugnenabled is in that specific class not set and in all others it is set…
Not sure if I’m following… are you saying for .NET Core to NOT use the ServiceStack way as indicated in the docsLogManager.LogFactory = new SerilogFactory(); and instead use the ASP.NET Core Logging way and ServiceStack will automatically set the LogFactory?
I’m assuming Install-Package ServiceStack.Logging.Serilog still is a requirement?
Maybe a .NET Core version/section should be added to the logging docs
Yeah for ASP .NET Core ServiceStack automatically populatesLogManager.LogFactory with a NetCoreLogFactory which delegates logging messages to ASP .NET Core’s Microsoft.Extensions.Logging.ILogger API which uses your App’s configured ASP .NET Core logging provider, so there’s no reason to use to use & configure 2 different logging implementations, just use your ASP .NET Core’s logging provider.
A lot of logging providers have .NET Standard 2.0 implementations so you can continue to use ServiceStack’s logging adapters, but I’d personally just let it use your ASP .NET Core App’s configured logging.
If needed, you can also reset OrmLite’s static logging providers to use ASP .NET Core’s logger with:
var logFactory = ApplicationServices.GetService<ILoggerFactory>();