{"id":19244376,"url":"https://github.com/nanoframework/nanoframework.logging","last_synced_at":"2026-05-11T03:27:54.399Z","repository":{"id":37198214,"uuid":"355979239","full_name":"nanoframework/nanoFramework.Logging","owner":"nanoframework","description":"📦 A logging library for .NET nanoFramework compatible with Microsoft.Extensions.Logging.","archived":false,"fork":false,"pushed_at":"2026-04-29T01:41:30.000Z","size":538,"stargazers_count":6,"open_issues_count":0,"forks_count":8,"subscribers_count":4,"default_branch":"main","last_synced_at":"2026-04-29T01:51:52.014Z","etag":null,"topics":["chsarp","dotnet","embedded-systems","hacktoberfest","logging","nanoframework"],"latest_commit_sha":null,"homepage":"https://www.nanoframework.net","language":"C#","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nanoframework.png","metadata":{"funding":{"open_collective":"nanoframework","github":"nanoframework"},"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-04-08T16:30:45.000Z","updated_at":"2026-03-09T22:32:16.000Z","dependencies_parsed_at":"2025-12-11T05:09:40.540Z","dependency_job_id":null,"html_url":"https://github.com/nanoframework/nanoFramework.Logging","commit_stats":{"total_commits":316,"total_committers":9,"mean_commits":"35.111111111111114","dds":0.4715189873417721,"last_synced_commit":"dfef57b10aefe99063ddffaf63f323d48cf723ea"},"previous_names":[],"tags_count":172,"template":false,"template_full_name":null,"purl":"pkg:github/nanoframework/nanoFramework.Logging","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoframework%2FnanoFramework.Logging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoframework%2FnanoFramework.Logging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoframework%2FnanoFramework.Logging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoframework%2FnanoFramework.Logging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nanoframework","download_url":"https://codeload.github.com/nanoframework/nanoFramework.Logging/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoframework%2FnanoFramework.Logging/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32408506,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T02:37:21.628Z","status":"ssl_error","status_checked_at":"2026-04-29T02:36:50.947Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["chsarp","dotnet","embedded-systems","hacktoberfest","logging","nanoframework"],"created_at":"2024-11-09T17:23:08.931Z","updated_at":"2026-04-29T03:09:01.096Z","avatar_url":"https://github.com/nanoframework.png","language":"C#","funding_links":["https://opencollective.com/nanoframework","https://github.com/sponsors/nanoframework"],"categories":[],"sub_categories":[],"readme":"[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=nanoframework_nanoFramework.Logging\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=nanoframework_nanoFramework.Logging) [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=nanoframework_nanoFramework.Logging\u0026metric=reliability_rating)](https://sonarcloud.io/dashboard?id=nanoframework_nanoFramework.Logging) [![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) [![NuGet](https://img.shields.io/nuget/dt/nanoFramework.Logging.svg?label=NuGet\u0026style=flat\u0026logo=nuget)](https://www.nuget.org/packages/nanoFramework.Logging/) [![#yourfirstpr](https://img.shields.io/badge/first--timers--only-friendly-blue.svg)](https://github.com/nanoframework/Home/blob/main/CONTRIBUTING.md) [![Discord](https://img.shields.io/discord/478725473862549535.svg?logo=discord\u0026logoColor=white\u0026label=Discord\u0026color=7289DA)](https://discord.gg/gCyBu8T)\n\n![nanoFramework logo](https://raw.githubusercontent.com/nanoframework/Home/main/resources/logo/nanoFramework-repo-logo.png)\n\n-----\n\n### Welcome to the .NET **nanoFramework** nanoFramework.Logging Library repository\n\n## Build status\n\n| Component | Build Status | NuGet Package |\n|:-|---|---|\n| nanoFramework.Logging | [![Build Status](https://dev.azure.com/nanoframework/nanoframework.Logging/_apis/build/status/nanoFramework.Logging?repoName=nanoframework%2FnanoFramework.Logging\u0026branchName=main)](https://dev.azure.com/nanoframework/nanoframework.Logging/_build/latest?definitionId=71\u0026repoName=nanoframework%2FnanoFramework.Logging\u0026branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.Logging.svg?label=NuGet\u0026style=flat\u0026logo=nuget)](https://www.nuget.org/packages/nanoFramework.Logging/) |\n| nanoFramework.Logging.Serial | [![Build Status](https://dev.azure.com/nanoframework/nanoframework.Logging/_apis/build/status/nanoFramework.Logging?repoName=nanoframework%2FnanoFramework.Logging\u0026branchName=main)](https://dev.azure.com/nanoframework/nanoframework.Logging/_build/latest?definitionId=71\u0026repoName=nanoframework%2FnanoFramework.Logging\u0026branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.Logging.Serial.svg?label=NuGet\u0026style=flat\u0026logo=nuget)](https://www.nuget.org/packages/nanoFramework.Logging.Serial/) |\n| nanoFramework.Logging.Stream | [![Build Status](https://dev.azure.com/nanoframework/nanoframework.Logging/_apis/build/status/nanoFramework.Logging?repoName=nanoframework%2FnanoFramework.Logging\u0026branchName=main)](https://dev.azure.com/nanoframework/nanoframework.Logging/_build/latest?definitionId=71\u0026repoName=nanoframework%2FnanoFramework.Logging\u0026branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.Logging.Stream.svg?label=NuGet\u0026style=flat\u0026logo=nuget)](https://www.nuget.org/packages/nanoFramework.Logging.Stream/) |\n| nanoFramework.Logging.Syslog | [![Build Status](https://dev.azure.com/nanoframework/nanoframework.Logging/_apis/build/status/nanoFramework.Logging?repoName=nanoframework%2FnanoFramework.Logging\u0026branchName=main)](https://dev.azure.com/nanoframework/nanoframework.Logging/_build/latest?definitionId=71\u0026repoName=nanoframework%2FnanoFramework.Logging\u0026branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.Logging.Syslog.svg?label=NuGet\u0026style=flat\u0026logo=nuget)](https://www.nuget.org/packages/nanoFramework.Logging.Syslog/) |\n\n## Feedback and documentation\n\nFor documentation, providing feedback, issues and finding out how to contribute please refer to the [Home repo](https://github.com/nanoframework/Home).\n\nJoin our Discord community [here](https://discord.gg/gCyBu8T).\n\n## Credits\n\nThe list of contributors to this project can be found at [CONTRIBUTORS](https://github.com/nanoframework/Home/blob/main/CONTRIBUTORS.md).\n\n## License\n\nThe **nanoFramework** Class Libraries are licensed under the [MIT license](LICENSE.md).\n\n## Usage\n\nIn your class, make sure you have a global ILogger declared and in your constructor that you call `_logger = this.GetCurrentClassLogger();`\n\n```csharp\nusing Microsoft.Extensions.Logging;\nusing nanoFramework.Logging;\nusing System;\n\nnamespace UnitTestDebugLogging\n{\n    internal class MyTestComponent\n    {\n        private ILogger _logger;\n\n        public MyTestComponent()\n        {\n            _logger = this.GetCurrentClassLogger();\n        }\n\n        public void DoSomeLogging()\n        {\n            _logger.LogInformation(\"An informative message\");\n            _logger.LogError(\"An error situation\");\n            _logger.LogWarning(new Exception(\"Something is not supported\"), \"With exception context\");\n        }\n    }\n}\n```\n\nIn your main code, you'll need to create a logger:\n\n```csharp\nLogDispatcher.LoggerFactory = new DebugLoggerFactory();\n// Then you can create your object and the logging will happen\nMyTestComponent test = new MyTestComponent();\ntest.DoSomeLogging();\n```\n\nYou can have 3 different types of logger: Debug, Serial and Stream.\n\n### Debug logger\n\nAs presented previously, you can use the Factory pattern:\n\n```csharp\nLogDispatcher.LoggerFactory = new DebugLoggerFactory();\n// Then you can create your object and the logging will happen\nMyTestComponent test = new MyTestComponent();\ntest.DoSomeLogging();\n```\n\nYou can as well directly create a DebugLogger:\n\n```csharp\nDebugLogger _logger;\n_logger = new DebugLogger(\"test\");\n_logger.MinLogLevel = LogLevel.Trace; \n_logger.LogTrace(\"This is a trace\");\n```\n\n### Serial logger\n\nYou can use the Factory pattern:\n\n```csharp\nLogDispatcher.LoggerFactory = new SerialLoggerFactory(\"COM6\");\n// Then you can create your object and the logging will happen\nMyTestComponent test = new MyTestComponent();\ntest.DoSomeLogging();\n```\n\nNote that you can adjust the baud speed and all other elements.\n\nOr directly using a SerialLogger:\n\n```csharp\nSerialPort _serial;\n_serial = new SerialPort(\"COM6\", 115200);\nSerialLogger _logger = new SerialLogger(ref _serial);\n_logger.MinLogLevel = LogLevel.Trace; \n_logger.LogTrace(\"This is a trace\");\n```\n\n**Important**: make sure to refer to the documentation of your board to understand how to properly setup the serial port. The tests include an example with an ESP32.\n\n### Stream logger\n\nSimilar as for the others, you can either use a FileStream or a Stream in the LoggerFactory:\n\n```csharp\nMemoryStream memoryStream = new MemoryStream();\nLogDispatcher.LoggerFactory = new StreamLoggerFactory(memoryStream);\nMyTestComponent test = new MyTestComponent();\ntest.DoSomeLogging();\n```\n\nAnd you can as well use it directly:\n\n```csharp\nvar _stream = new FileStream(\"D:\\\\mylog.txt\", FileMode.Open, FileAccess.ReadWrite);\nStreamLogger _logger = new StreamLogger(_stream);\n_logger.MinLogLevel = LogLevel.Trace; \n_logger.LogTrace(\"This is a trace\");\n```\n\n**Important**: please refer to the documentation for USB and SD Card reader to make sure they are properly setup before trying to setup the logger.\n\n### Create your own logger\n\nYou can create your own logger using the ILogger and ILoggerFactory interfaces. The DebugLogger is the simplest one.\n\n### The Log extensions\n\nDifferent Log extensions are at your disposal to help you log the way you like. You can simply log a string or having parameters as well as exception and EventId:\n\n```csharp\n_logger.LogTrace(\"TRACE {0} {1}\", new object[] { \"param 1\", 42 });\n_logger.LogDebug(\"DEBUG {0} {1}\", new object[] { \"param 1\", 42 });\n_logger.LogInformation(\"INFORMATION and nothing else\");\n_logger.LogWarning(\"WARNING {0} {1}\", new object[] { \"param 1\", 42 });\n_logger.LogError(new Exception(\"Big problem\"), \"ERROR {0} {1}\", new object[] { \"param 1\", 42 });\n_logger.LogCritical(42, new Exception(\"Insane problem\"), \"CRITICAL {0} {1}\", new object[] { \"param 1\", 42 });\n```\n\nNote that all log level extensions have a minimum of string logging upo to EventId, string, parameters and exception. You are responsible to format properly the string when there are parameters.\n\n### Log level\n\nYou can adjust the log level in all the predefined logger. For example:\n\n```csharp\nDebugLogger _logger;\n_logger = new DebugLogger(\"test\");\n_logger.MinLogLevel = LogLevel.Trace;\n_logger.LogTrace(\"This will be displayed\");\n_logger.LogCritical(\"Critical message will be displayed\");\n_logger.MinLogLevel = LogLevel.Critical;\n_logger.LogTrace(\"This won't be displayed, only critical will be\");\n_logger.LogCritical(\"Critical message will be displayed\");\n```\n\n### Create your own formatting\n\nYou can use a custom formatter which will give you the name of the logger, the log level, the event ID, the message itself and a potential exception. The function definition should follow the following pattern:\n\n```csharp\npublic interface IMessageFormatter\n{     \n    string MessageFormatter(string className, LogLevel logLevel, EventId eventId, string state, Exception exception);\n}\n```\n\n**Important**: this function will be called directly, without instantiating the class it is part of. So make sure either this function is a static, either it's part of the class using the logger. The static option always works. The interface is given for convenience and to give the format.\n\nTo setup the formatting, just use the following line. The type of the class containing the function and the exact name of the function are required.\n\n```csharp\nLoggerExtensions.MessageFormatter = typeof(MyFormatter).GetType().GetMethod(\"MessageFormatterStatic\");\n\npublic class MyFormatter\n{        \n    public string MessageFormatterStatic(string className, LogLevel logLevel, EventId eventId, string state, Exception exception)\n    {\n        string logstr = string.Empty;\n        switch (logLevel)\n        {\n            case LogLevel.Trace:\n                logstr = \"TRACE: \";\n                break;\n            case LogLevel.Debug:\n                logstr = \"I love debug: \";\n                break;\n            case LogLevel.Warning:\n                logstr = \"WARNING: \";\n                break;\n            case LogLevel.Error:\n                logstr = \"ERROR: \";\n                break;\n            case LogLevel.Critical:\n                logstr = \"CRITICAL:\";\n                break;\n            case LogLevel.None:\n            case LogLevel.Information:\n            default:\n                break;\n        }\n\n        string eventstr = eventId.Id != 0 ? $\" Event ID: {eventId}, \" : string.Empty;\n        string msg = $\"[{className}] {eventstr}{logstr} {state}\";\n        if (exception != null)\n        {\n            msg += $\" {exception}\";\n        }\n\n        return msg;\n    }\n}\n```\n\nYou are free to use anything you'd like and format as you like the message.\n\nNote: It is **not** necessary to add a \\r\\n at the end, this is done by each logger.\n\n## Code of Conduct\n\nThis project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behaviour in our community.\nFor more information see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct).\n\n## .NET Foundation\n\nThis project is supported by the [.NET Foundation](https://dotnetfoundation.org).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanoframework%2Fnanoframework.logging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnanoframework%2Fnanoframework.logging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanoframework%2Fnanoframework.logging/lists"}