-
Notifications
You must be signed in to change notification settings - Fork 450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove filters for ILoggers created by customer DI #4345
Comments
@brettsam Thanks for the host.json workaround. Is there a way to specify log levels differently for development vs production environments? |
@brettsam when you say:
And then my host.json:
I still don't get any logs. What am I missing? |
@brettsam sorry, I've just found the answer to my own question by looking at this: #4425 (comment) |
You can reset all of the filters with this code in your Startup.cs (put it as late as possible): builder.Services.RemoveAll<IConfigureOptions<LoggerFilterOptions>>();
builder.Services.ConfigureOptions<LoggerFilterConfigureOptions>(); Where |
Are there any updates to this besides removing all the filters? |
No updates -- but the workaround above is fairly straightforward: #4345 (comment). Is this not working for you? |
In the host.json, the category filtering is not working for the root namespace for my solution. host.json {
"version": "2.0",
"logging": {
"logLevel": {
"default": "Information",
"MySolution": "Trace"
}
}
} Where I have a class that tries to use it that gets injected into the function... namespace MySolution.Things {
public class Thing1 {
public Thing1(ILogger<Thing1> logger) => logger.LogTrace("this is a trace from thing1");
}
} It does work if I use the full namespace + class name for the category in the host.json, e.g. |
@smokedlinq -- is this happening in production, or locally using the core tools? |
I have only noticed locally while debugging. |
Can you share what version of the core tools and functions host you're running (it should be the first few lines of output in the console when you start your app). @pragnagopa -- maybe another issue here with the logging setup in core tools. |
@brettsam It's been 18 months since you filed this - when is it going to be implemented? Logging is one of the most important parts of any application. Getting it right should thus be the first priority of any framework. I know Microsoft wants new features to sell Azure with, but Functions' logging woes need to get sorted out for once and for all. |
@smokedlinq - Core Tools regression is fixed in the latest version: https://github.com/Azure/azure-functions-core-tools/releases/tag/3.0.2931 - if filter is still not working please open a separate issue here: https://github.com/Azure/azure-functions-core-tools/ |
Just confirmed, 3.0.2931 does behave as expected. Thanks all. |
I think I'm seeing this problem as well. I've created an Azure Service Bus function. The function uses a DI container using .NET Core's own DI libraries. The function entry point receives an ILogger instance and we see log entries made with this instance. However, any log entries made with any generic instances of The current function runtime is So far, I have tried ...
In my function, I do setup my DI container like so ..
At this point, I'm debating rewriting my function and DI container to pass around the Any help would be appreciated. Thanks. |
otherwise it would only be shown in Live Metrics, but not in console or in actual AppInsights logs. see Azure/azure-functions-host#4345
I have the same issue thant @abjbhat and I would love to have a workaround :( |
I am hitting the same issue, did you find a work around ? @jonathanantoine @abjbhat |
My solution was just to take the //YourFunction.cs
public static void Run(/*other parameters*/, ILogger logger){
YourDependencyInjection.Create(logger)
}
//YourDependencyInjection.cs
private void Create(ILogger logger, ServiceCollection services){
services.AddScoped< ILoggerWrapper, LoggerWrapper>(builder => new LoggerWrapper(logger))
}
//ILoggerWrapper.cs maybe defined in a different project/dll. Add whatever methods you need
public interface ILoggerWrapper{
void LogInfo();
void LogError();
}
//LoggerWrapper
public class LoggerWrapper : ILoggerWrapper{
public LoggerWrapper(ILogger logger) {
//save the reference
}
}
//DependentComponentService.cs
public class DependentComponentService{
public DependentComponentService(ILoggerWrapper loggerWrapper){
//save the reference
}
} This worked for me. I can now see logs in AppInsights. I couldn't see them earlier. |
Is this issue still being worked on? Logging shouldn't be this hard to set up. If I have to troubleshoot to get my logs working, that's time that I waste not working on the app. I've added my namespace to the host.json and I'm still not seeing my custom logs. These 'workarounds' are great but I think it's ridiculous how I need to add more code than what's in my whole program just to see logs. Are we going to get a proper solution to this or is this inconsistent host.json workaround all we get? |
I agree that it is so ridiculous. Although I set min log level to
host.json
csproj
The function is set up not to send logs directly to Application Insights ( |
We need to be less restrictive on filtering logging categories. Today if someone creates a logger that is not in one of our "accepted" lists, we'll filter it away. You can get around this by adding one or more filters to get those categories flowing again, but this shouldn't be necessary.
The below settings will allow any category that starts with "OrderService" to be logged at "Information" and above levels.
The text was updated successfully, but these errors were encountered: