{"id":28328469,"url":"https://github.com/nosratifarhad/serilog_dotnet6","last_synced_at":"2026-04-27T08:31:59.887Z","repository":{"id":161113719,"uuid":"635850081","full_name":"nosratifarhad/Serilog_DotNet6","owner":"nosratifarhad","description":" In this repository, you can see the features of Serilog and how to set it up and use it.","archived":false,"fork":false,"pushed_at":"2023-11-29T16:49:17.000Z","size":1141,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-24T08:43:42.845Z","etag":null,"topics":["dotnet-core","log","logger","logging","serilog"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nosratifarhad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-05-03T15:28:45.000Z","updated_at":"2023-11-29T16:53:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"9ca4054a-8742-4aed-ac49-935958b3d3a4","html_url":"https://github.com/nosratifarhad/Serilog_DotNet6","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nosratifarhad/Serilog_DotNet6","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nosratifarhad%2FSerilog_DotNet6","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nosratifarhad%2FSerilog_DotNet6/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nosratifarhad%2FSerilog_DotNet6/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nosratifarhad%2FSerilog_DotNet6/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nosratifarhad","download_url":"https://codeload.github.com/nosratifarhad/Serilog_DotNet6/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nosratifarhad%2FSerilog_DotNet6/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32329463,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"online","status_checked_at":"2026-04-27T02:00:06.769Z","response_time":128,"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":["dotnet-core","log","logger","logging","serilog"],"created_at":"2025-05-26T06:17:06.493Z","updated_at":"2026-04-27T08:31:59.875Z","avatar_url":"https://github.com/nosratifarhad.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Serilog In .Net 6\n\n### First you need to install the following packages :\n\n\u003e Note : Whatever you need, don't install it\n\n``` bash\ndotnet add package Serilog.Sinks.Seq\ndotnet add package Serilog.Sinks.MSSqlServer\ndotnet add package Serilog.Sinks.File\ndotnet add package Serilog.Sinks.Console\ndotnet add package Serilog.AspNetCore\ndotnet add package Serilog\n```\n\n### Now you must add following code in program.cs \n\n```csharp\nLog.Logger = new LoggerConfiguration()\n        //...\n        // Set Configuration Between two Line\n        //...\n        .CreateLogger(); //OR .CreateBootstrapLogger();\n\n```\n### your can add configs from 'appsettings.json' OR Hard Code\n### if you want user 'appsettings.json' you must add following code before create instance from \"LoggerConfiguration\"\n```csharp\nvar configuration = new ConfigurationBuilder()\n      .SetBasePath(Directory.GetCurrentDirectory())\n      .AddJsonFile(\"appsettings.json\", optional: false, reloadOnChange: true)\n      .Build();\n```\n\n### You can use this command to set all the configurations specified in the appsettings.json file at once, eliminating the need to add the following items separately.\n\u003e this code should be added between the two lines above.\n```csharp\nLog.Logger = new LoggerConfiguration()\n\n    .ReadFrom.Configuration(configuration)\n\n    .CreateLogger();\n```\n### Note: If you use this command, there is no need to add the items mentioned below separately.\n\n### If you want to add ThreadId to field loggers, you can utilize this method similar to how threads are used.\n// If You Dont Need , Remove this Line.\n```csharp\nLog.Logger = new LoggerConfiguration()\n    //...\n    .Enrich.With(new ThreadIdEnricher())\n    //...\n    .CreateLogger();\n```\n### you shuld create lower class for user to above code .\n```csharp\npublic class ThreadIdEnricher : ILogEventEnricher\n{\n    public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)\n    {\n        logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(\n                \"ThreadId\", Thread.CurrentThread.ManagedThreadId));\n    }\n}\n```\n### To write logs to the console, you can use the following syntax.\n// If You Dont Need , Remove this Line.\n```csharp\n//.WriteTo.Console()\n// OR\n.WriteTo.Console(outputTemplate: \"{Timestamp:HH:mm} [{Level}] ({ThreadId}) {Message}{NewLine}{Exception}\")\n```\n![My Remote Image](https://github.com/nosratifarhad/Serilog_DotNet6/blob/main/imgs/Annotation2.jpg)\n\n### For Write Logs in Json File , If You Dont Need , Remove this Line.\n```csharp\n.WriteTo.File(new CompactJsonFormatter(), \"log/jsonLog.json\", shared: true)\n```\n```json\n{...},\n{\n  \"Timestamp\": \"2023-11-29T19:39:08.4114614+03:30\",\n  \"Level\": \"Information\",\n  \"MessageTemplate\": \"HTTP {RequestMethod} {RequestPath} responded {StatusCode} in {Elapsed:0.0000} ms\",\n  \"Properties\": {\n    \"RequestMethod\": \"POST\",\n    \"RequestPath\": \"/api/products\",\n    \"StatusCode\": 201,\n    \"Elapsed\": 185.8472,\n    \"SourceContext\": \"Serilog.AspNetCore.RequestLoggingMiddleware\",\n    \"RequestId\": \"0HMVGULPKORR8:00000021\",\n    \"ConnectionId\": \"0HMVGULPKORR8\",\n    \"Application\": \"ECommerceSerilog\"\n  },\n  \"Renderings\": {\n    \"Elapsed\": [\n      {\n        \"Format\": \"0.0000\",\n        \"Rendering\": \"185.8472\"\n      }\n    ]\n  }\n}\n```\n![My Remote Image](https://github.com/nosratifarhad/Serilog_DotNet6/blob/main/imgs/Annotation3.jpg)\n![My Remote Image](https://github.com/nosratifarhad/Serilog_DotNet6/blob/main/imgs/Annotation5.jpg)\n\n### For Write Logs in txt File And Set Options From Hear , If You Dont Need , Remove this Line.\n```csharp\n//.WriteTo.File(\"log/diagnostics.txt\")\n// OR\n//.WriteTo.File(\n//     Path.Combine(\"log\", \"diagnostics.txt\"),\n//     rollingInterval: RollingInterval.Day,\n//     fileSizeLimitBytes: 10 * 1024 * 1024,\n//     retainedFileCountLimit: 2,\n//     rollOnFileSizeLimit: true,\n//     shared: true,\n//     flushToDiskInterval: TimeSpan.FromSeconds(1),\n//     outputTemplate: \"{Timestamp:HH:mm} [{Level}] ({ThreadId}) {Message}{NewLine}{Exception}\")\n```\nدو\n### // For Show Logs In Serilog pannel And Set Options From Hear , If You Dont Need , Remove this Line.\n```csharp\n.WriteTo.Seq(\"http://localhost:5341\", Serilog.Events.LogEventLevel.Warning)\n```\nدو\n// For Write Logs in txt File And Set Options From \"ConfigurationBuilder\" , If You Dont Need , Remove this Line.\n```csharp\n.AuditTo.File(\"log/diagnostics.txt\")\n```\n### // For Write Logs in Sql Database And Set Options From Hear , If You Dont Need , Remove this Line.\n\n```csharp\n.WriteTo.MSSqlServer(\"Data Source=(localdb)\\\\MSSqlLocalDb;Initial Catalog=LoggingDb;persist security info=True;\",\n                    new MSSqlServerSinkOptions\n                    {\n                        TableName = \"Logs\",\n                        SchemaName = \"dbo\",\n                        AutoCreateSqlTable = true\n                    })\n.MinimumLevel.Override(\"Microsoft.AspNetCore\", LogEventLevel.Warning)\n```\n![My Remote Image](https://github.com/nosratifarhad/Serilog_DotNet6/blob/main/imgs/Annotation.jpg)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnosratifarhad%2Fserilog_dotnet6","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnosratifarhad%2Fserilog_dotnet6","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnosratifarhad%2Fserilog_dotnet6/lists"}