{"id":24129361,"url":"https://github.com/pawelgerr/thinktecture.logging.configuration","last_synced_at":"2025-06-23T17:33:38.438Z","repository":{"id":60773455,"uuid":"102524566","full_name":"PawelGerr/Thinktecture.Logging.Configuration","owner":"PawelGerr","description":"Library for (temporary) change of the log level.","archived":false,"fork":false,"pushed_at":"2020-06-24T07:52:25.000Z","size":63,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-09T04:06:35.379Z","etag":null,"topics":["configuration","dotnet","dotnet-core","logging"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PawelGerr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-05T20:02:38.000Z","updated_at":"2024-02-27T15:50:49.000Z","dependencies_parsed_at":"2022-10-04T15:26:20.274Z","dependency_job_id":null,"html_url":"https://github.com/PawelGerr/Thinktecture.Logging.Configuration","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PawelGerr%2FThinktecture.Logging.Configuration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PawelGerr%2FThinktecture.Logging.Configuration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PawelGerr%2FThinktecture.Logging.Configuration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PawelGerr%2FThinktecture.Logging.Configuration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PawelGerr","download_url":"https://codeload.github.com/PawelGerr/Thinktecture.Logging.Configuration/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233526148,"owners_count":18689438,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configuration","dotnet","dotnet-core","logging"],"created_at":"2025-01-11T19:31:31.408Z","updated_at":"2025-01-11T19:31:36.531Z","avatar_url":"https://github.com/PawelGerr.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build status](https://ci.appveyor.com/api/projects/status/ijstyxit8tn7baex?svg=true)](https://ci.appveyor.com/project/PawelGerr/thinktecture-logging-configuration)  \n[![Thinktecture.Extensions.Logging.Configuration](https://img.shields.io/nuget/v/Thinktecture.Extensions.Logging.Configuration.svg?label=Thinktecture.Extensions.Logging.Configuration\u0026maxAge=3600)](https://www.nuget.org/packages/Thinktecture.Extensions.Logging.Configuration/)  \n[![Thinktecture.Extensions.Serilog.Configuration](https://img.shields.io/nuget/v/Thinktecture.Extensions.Serilog.Configuration.svg?label=Thinktecture.Extensions.Serilog.Configuration\u0026maxAge=3600)](https://www.nuget.org/packages/Thinktecture.Extensions.Serilog.Configuration/)\n\nAllows to change the log level at runtime.\nIt is usefull for pinpointing issues in production environments by changing to lower log level like `Debug` temporarily (for example via GUI or Web API) without restarting the application.\n\nThere are 2 projects/nuget packages:\n* Use `Thinktecture.Extensions.Logging.Configuration` in case you are using `Microsoft.Extensions.Logging.ILogger`\n* Use `Thinktecture.Extensions.Serilog.Configuration` with `Serilog.ILogger`\n\n## Usage\n\nThe steps for setting up the configuration for `ILogger` from Microsoft and [Serilog](https://github.com/serilog/serilog) are almost identical.\n\n### With *Microsoft.Extensions.Logging.ILogger*\n\n[Example](https://github.com/PawelGerr/Thinktecture.Logging.Configuration/blob/master/example/Thinktecture.Extensions.Logging.Configuration.Example/Program.cs)\n\n`Install-Package Thinktecture.Extensions.Logging.Configuration`\n\nCreate an instance of `ILoggingConfiguration`\n\n```\n// You can register this instance (i.e. ILoggingConfiguration) with DI\n// and, for example, control the logging level via GUI or Web API\nvar loggingConfig = new LoggingConfiguration();\n```\n\nAdd the logging configuration to your `IConfigurationBuilder` using extension method `AddLoggingConfiguration`.\nThis call must be placed after other configuration providers that change the log level, e.g. as the last one.\n\n```\nvar config = new ConfigurationBuilder()\n\t// Adding JsonFile just to provide some defaults\n\t.AddJsonFile(\"appsettings.json\", false, true)\n\t// The following line is the only one that's new.\n\t// The path to the logging config is \"My:Logging\" in this example\n\t.AddLoggingConfiguration(loggingConfig, \"My\", \"Logging\")\n\t.Build();\n\n== appsettings.json =============================================\n\"My\": {\n\t\"Logging\": {\n\t\t...\n\t}\n}\n```\n\nUse the `IConfiguration` to configure the logger [the usual way](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging#log-filtering).\n\n```\nvar serviceProvider = new ServiceCollection()\n\t.AddLogging(builder =\u003e\n\t{\n\t\t// Nothing new, provide IConfiguration the usual way\n\t\tbuilder.AddConfiguration(config.GetSection(\"My:Logging\"));\n\t\tbuilder.AddConsole();\n\t})\n\t.BuildServiceProvider();\n```\n\nUse `ILoggingConfiguration` to set and reset the log level.\n\n```\nILoggingConfiguration loggingConfig = ...;\n\n//Changing log level of category=Thinktecture and provider=all to Warning\nloggingConfig.SetLevel(LogLevel.Warning, \"Thinktecture\");\n\n// Changing log level of category=all and provider=Console to Error\nloggingConfig.SetLevel(LogLevel.Error, null, \"Console\");\n\n// Changing log level of category=Thinktecture and provider=Console to Critical\nloggingConfig.SetLevel(LogLevel.Critical, \"Thinktecture\", \"Console\");\n\n// Resetting all settings, returning to defaults\nloggingConfig.ResetLevel();\n```\n\n### With *Serilog*\n\n[Example](https://github.com/PawelGerr/Thinktecture.Logging.Configuration/blob/master/example/Thinktecture.Extensions.Serilog.Configuration.Example/Program.cs)\n\n`Install-Package Thinktecture.Extensions.Serilog.Configuration`\n\nCreate an instance of `ISerilogConfiguration`\n\n```\n// You can register this instance (i.e. ISerilogConfiguration) with DI\n// and, for example, control the logging level via GUI or Web API\nvar loggingConfig = new SerilogConfiguration();\n```\n\nAdd the logging configuration to your `IConfigurationBuilder` using extension method `AddLoggingConfiguration`.\nThis call must be placed after other configuration providers that change the log level, e.g. as the last one.\n\n\u003e **Limitation**: Serilog creates *a watcher* (i.e. a `LoggingLevelSwitch`) for configuration keys only that are present when building the logger.\n\u003e For example: if there is no configuration for `MinimumLevel:Override:Thinktecture` when CreateLogger() is called then you won't be able to change the log level for this category during runtime.\n\n```\nvar config = new ConfigurationBuilder()\n\t// Adding JsonFile to provide defaults.\n\t.AddJsonFile(\"appsettings.json\", false, true)\n\t// The following line is the only one that's new.\n\t// The path to the logging config is \"My:Serilog\" in this example\n\t.AddLoggingConfiguration(loggingConfig, \"My\", \"Serilog\")\n\t.Build();\n\n== appsettings.json =============================================\n\n\"My\": {\n\t\"Serilog\": {\n\t\t...\n\t}\n}\n```\n\nUse the `IConfiguration` to configure Serilog according to [Serilog.Settings.Configuration](https://github.com/serilog/serilog-settings-configuration)\n\n```\nvar loggerConfiguration = new LoggerConfiguration()\n\t.ReadFrom.ConfigurationSection(config.GetSection(\"My:Serilog\"))\n\t.WriteTo.Console();\n```\n\nUse `ISerilogConfiguration` to set and reset log level.\n\n```\nISerilogConfiguration serilogConfig = ...;\n\n// Changing log level of category=all to Information\nserilogConfig.SetLevel(LogEventLevel.Information);\n\n// Changing log level of category=Thinktecture to Debug\nserilogConfig.SetLevel(LogEventLevel.Debug, \"Thinktecture\");\n\nResetting all settings, returning to defaults\nserilogConfig.ResetLevel();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpawelgerr%2Fthinktecture.logging.configuration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpawelgerr%2Fthinktecture.logging.configuration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpawelgerr%2Fthinktecture.logging.configuration/lists"}