Is there a way to output the INSERT, UPDATE, DELETE statements in the console log during debug. Now I only see the SELECT statements being logged (.net core).
I am configuring everyhting and then execute:
LogManager.LogFactory = new SerilogFactory();
And I specified
var loggerConfiguration = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Error)
.Enrich.FromLogContext()
.WriteTo.Console();
So the Debug level is included.
I only see the SELECT. Sample
2019-05-02 17:18:37 [Debug] SQL: SELECT "IdxConsumerId", "Id", "Data", "Updated"
FROM "bot_ConsumerSessionObject"
WHERE ("IdxConsumerId" = @0)
PARAMS: @0=0b74bdbc-72eb-4ea6-9b13-17d38314e4b2
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.
So, I subclassed the AppHostBase and override the Bind
public override void Bind(IApplicationBuilder app)
{
base.Bind(app); // THIS WILL OVERRIDE Factory To Default NetCore
LogManager.LogFactory = new SerilogFactory();
}
now the SerilogFactory is back overriden and everything works.
Shouldn’t be the case that I have to do this I guess?
It’s being overridden by NetCoreLogFactory which should use your configured .UseSerilog() configuration, why are you overriding it with SerilogFactory?
Did you want the AppHost to not override it if you’ve set it?
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>();
OrmLiteConfig.ResetLogFactory(new NetCoreLogFactory(logFactory));
Right. So where would be the best place include the below line of code to reset the OrmLiteConfig? At anytime in Startup.Configure()? Probably right away in Startup.Configure()?