Foxtrek_64
Foxtrek_64
Explore posts from servers
CC#
Created by Foxtrek_64 on 11/22/2024 in #help
Custom Logger
I was able to figure it out. My SqlServer library was named Microsoft.Extensions.Logging.SqlServer and the tests library adds the .Tests node to the namespace. It was correctly pulling in appsettings data that told it that
{
"Logging:LogLevel:Microsoft": "Warning"
}
{
"Logging:LogLevel:Microsoft": "Warning"
}
So naturally an information message was being excluded. I created a new type with a new namespace in my test library to simulate a consumer and now everything is happy
14 replies
CC#
Created by Foxtrek_64 on 11/22/2024 in #help
Custom Logger
This is the important part of the body of the database logger. I'm not hitting the if check to see if the logger is enabled though.
public bool IsEnabled(LogLevel logLevel)
{
return options.LevelSwitch is not LogLevel.None && logLevel >= options.LevelSwitch;
}

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
if (IsEnabled(logLevel))
{
logAgent.WriteToDatabase(logLevel, eventId, state, exception, formatter);
}
}
public bool IsEnabled(LogLevel logLevel)
{
return options.LevelSwitch is not LogLevel.None && logLevel >= options.LevelSwitch;
}

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
if (IsEnabled(logLevel))
{
logAgent.WriteToDatabase(logLevel, eventId, state, exception, formatter);
}
}
14 replies
CC#
Created by Foxtrek_64 on 11/22/2024 in #help
Custom Logger
But I'm not hitting any breakpoints inside of the logger nor the log agent.
14 replies
CC#
Created by Foxtrek_64 on 11/22/2024 in #help
Custom Logger
I do see a lot of calls to my logger provider's CreateLogger() function
public ILogger CreateLogger(string categoryName)
=> _loggers.GetOrAdd(categoryName, name => new MSSqlDatabaseLogger(name, _currentConfig, _logAgent, _scopeProvider));
public ILogger CreateLogger(string categoryName)
=> _loggers.GetOrAdd(categoryName, name => new MSSqlDatabaseLogger(name, _currentConfig, _logAgent, _scopeProvider));
_loggers is a concurrent dictionary (made it that in case of this being issues with async, but it can probaby be a regular dictionary) of string, MSSqlDatabaseLogger. The current options are provided by IOptionsMonitor<> And the scope provider is an IExternalScopeProvider instance, which defaults to a no-op scope shamelessly copied from the M.E.L.Console no-scope provider.
14 replies
CC#
Created by Foxtrek_64 on 11/22/2024 in #help
Custom Logger
Everything is synchronous in my db access library. There could be some asynchronicity with regards to the application host though.
14 replies
CC#
Created by Foxtrek_64 on 11/22/2024 in #help
Custom Logger
Not sure how to see the output from that console logger in an xunit process
14 replies
CC#
Created by Foxtrek_64 on 11/22/2024 in #help
SqlConnection Connection Disposed
I've got the test to a state where it's passing. Thanks for your help.
13 replies