{"id":24554010,"url":"https://github.com/fkucukkara/highperformancelogging","last_synced_at":"2025-08-25T23:07:27.414Z","repository":{"id":271099407,"uuid":"909408569","full_name":"fkucukkara/highPerformanceLogging","owner":"fkucukkara","description":"This repository demonstrates the use of Source-Generated Logging in .NET for high-performance and efficient logging.","archived":false,"fork":false,"pushed_at":"2025-06-29T12:21:42.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-29T13:30:04.285Z","etag":null,"topics":["csharp","high-performance-logger","netcore-webapi","source-generator"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"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/fkucukkara.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2024-12-28T16:05:53.000Z","updated_at":"2025-06-29T12:21:45.000Z","dependencies_parsed_at":"2025-01-05T14:29:05.455Z","dependency_job_id":"f5027a38-f982-4ca5-a19b-75a305ab1e55","html_url":"https://github.com/fkucukkara/highPerformanceLogging","commit_stats":null,"previous_names":["fkucukkara/highperformancelogging"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fkucukkara/highPerformanceLogging","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fkucukkara%2FhighPerformanceLogging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fkucukkara%2FhighPerformanceLogging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fkucukkara%2FhighPerformanceLogging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fkucukkara%2FhighPerformanceLogging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fkucukkara","download_url":"https://codeload.github.com/fkucukkara/highPerformanceLogging/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fkucukkara%2FhighPerformanceLogging/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272144649,"owners_count":24881141,"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","status":"online","status_checked_at":"2025-08-25T02:00:12.092Z","response_time":1107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["csharp","high-performance-logger","netcore-webapi","source-generator"],"created_at":"2025-01-23T02:17:03.703Z","updated_at":"2025-08-25T23:07:27.365Z","avatar_url":"https://github.com/fkucukkara.png","language":"C#","readme":"# High-Performance Logging in .NET: Source-Generated Logger\n\nThis repository demonstrates the use of **Source-Generated Logging** in .NET for high-performance and efficient logging. By leveraging the `LoggerMessage` attribute, this approach minimizes runtime overhead, reduces memory allocations, and ensures better log performance compared to traditional logging techniques.\n\n## Features\n- **Optimized Logging**: Use of `LoggerMessage` for compile-time generated logging methods.\n- **Structured Log Messages**: Clear, consistent, and parameterized log messages.\n- **Event Name and Event ID**: Adds context to log entries, making them easier to identify and filter.\n- **Minimal API Integration**: Demonstrates integration of source-generated logging within a Minimal API project.\n\n## Why Use Source-Generated Logging?\nTraditional logging methods in .NET involve runtime string interpolation and object boxing, which can lead to performance overhead. Source-generated logging eliminates this by generating optimized code at compile time. This approach:\n\n- **Reduces Runtime Overhead**: No runtime string formatting or boxing of parameters.\n- **Improves Performance**: Ideal for high-throughput applications.\n- **Enhances Readability**: Provides well-structured, consistent log messages.\n\nFor more details, see the official documentation: [Logger Message Generator](https://learn.microsoft.com/en-us/dotnet/core/extensions/logger-message-generator).\n\n## Project Structure\n\n- **`Program.cs`**: Contains the Minimal API with a weather forecast endpoint that utilizes the source-generated logger.\n- **`LoggerExtensions.cs`**: Defines the logger extensions using the `LoggerMessage` attribute.\n- **`WeatherForecast.cs`**: Defines the model used in the weather forecast endpoint.\n\n## Usage\n\n### Logger Extensions\nThe source-generated logger is defined in the `LoggerExtensions.cs` file:\n\n```csharp\nnamespace API;\n\ninternal static partial class LoggerExtensions\n{\n    private const string GetWeatherForecastEvent = $\"{nameof(GetWeatherForecastEvent)}\";\n    private const string GetWeatherForecastEventTemplate = \"Getting weather forecast, item count = {Count}\";\n\n    [LoggerMessage(\n        EventName = GetWeatherForecastEvent,\n        Level = LogLevel.Information,\n        Message = GetWeatherForecastEventTemplate)]\n    internal static partial void LogGetWeatherForecast(\n        this ILogger\u003cProgram\u003e logger,\n        int count);\n}\n```\n\n### Minimal API Integration\nThe logger is used in the `/weatherforecast` endpoint in `Program.cs`:\n\n```csharp\napp.MapGet(\"/weatherforecast\", (ILogger\u003cProgram\u003e logger) =\u003e\n{\n    var forecast = Enumerable.Range(1, 5).Select(index =\u003e\n        new WeatherForecast\n        (\n            DateOnly.FromDateTime(DateTime.Now.AddDays(index)),\n            Random.Shared.Next(-20, 55),\n            summaries[Random.Shared.Next(summaries.Length)]\n        ))\n        .ToArray();\n\n    logger.LogGetWeatherForecast(forecast.Length);\n    return forecast;\n});\n```\n\n### Running the Application\n1. Clone the repository:\n\n   ```bash\n   git clone https://github.com/fkucukkara/highPerformanceLogging.git\n   cd src/API\n   ```\n\n2. Build and run the application:\n\n   ```bash\n   dotnet run\n   ```\n\n3. Access the weather forecast endpoint:\n\n   ```\n   http://localhost:5000/weatherforecast\n   ```\n\nLogs will display in the console, including the event name, level, and structured message.\n\n## Example Log Output\n\n```\ninfo: API.Program[0]\n      Getting weather forecast, item count = 5\n```\n\n### Note\nBy default, the event ID and event name are not visible in the output with the default configuration. This is intentional for simplicity. To view them, you can provide additional logging configurations.\n\n## Benefits Highlighted\n- **Event Name**: `GetWeatherForecastEvent`\n- **Message Template**: \"Getting weather forecast, item count = {Count}\"\n- **Optimized Performance**: No runtime formatting or boxing.\n\n## References\n- Official Documentation: [Logger Message Generator](https://learn.microsoft.com/en-us/dotnet/core/extensions/logger-message-generator)\n\n## License\n[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n\nThis project is licensed under the MIT License, which allows you to freely use, modify, and distribute the code. See the [`LICENSE`](LICENSE) file for full details.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffkucukkara%2Fhighperformancelogging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffkucukkara%2Fhighperformancelogging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffkucukkara%2Fhighperformancelogging/lists"}