{"id":37049276,"url":"https://github.com/oleksabor/nlog.indentexception","last_synced_at":"2026-01-14T05:43:48.667Z","repository":{"id":110850065,"uuid":"165677091","full_name":"oleksabor/nlog.indentexception","owner":"oleksabor","description":"custom NLog layoutRenderer allows to show exception using readable format (from my point of view) in the log (file or console). Additionally it does not log full exception stack trace if it is logged second time (it happens if exception is rethrown like inner exception)","archived":false,"fork":false,"pushed_at":"2024-01-09T20:01:46.000Z","size":17,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-20T06:24:50.654Z","etag":null,"topics":["nlog","nlog-layout-renderers"],"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/oleksabor.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-01-14T14:38:09.000Z","updated_at":"2024-01-25T01:27:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"d7fe315e-b387-4cdd-a495-7a2287963cbb","html_url":"https://github.com/oleksabor/nlog.indentexception","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/oleksabor/nlog.indentexception","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleksabor%2Fnlog.indentexception","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleksabor%2Fnlog.indentexception/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleksabor%2Fnlog.indentexception/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleksabor%2Fnlog.indentexception/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oleksabor","download_url":"https://codeload.github.com/oleksabor/nlog.indentexception/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleksabor%2Fnlog.indentexception/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28411226,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T05:26:33.345Z","status":"ssl_error","status_checked_at":"2026-01-14T05:21:57.251Z","response_time":107,"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":["nlog","nlog-layout-renderers"],"created_at":"2026-01-14T05:43:48.156Z","updated_at":"2026-01-14T05:43:48.662Z","avatar_url":"https://github.com/oleksabor.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"I've asked a question about [exception layout renderer at SO](https://stackoverflow.com/questions/46565639/nlog-exception-layout-to-format-exception-type-message-and-stack-trace)\n\nHowever seems that writing custom layout renderer is not so complex\nSo here i will keep IndentExceptionLayoutRenderer.cs source code\n\n[![NuGet](https://img.shields.io/nuget/v/NLog.IndentException.svg?maxAge=259200)](https://www.nuget.org/packages/NLog.IndentException/)\n\nThis renderer allows to show exception using readable format (from my point of view) in the log (file or console). Additionally it does not log full exception stack trace if it is logged second time (it happens if exception is rethrown like inner exception).\n\nsrc\\NLog.config is a sample configuration that shows how layout can be parameterized for console and file logging\n\nBelow you can find IndentException class properties that can help you to adjust exception logging\n\n| property name | description |\n|-----|------|\n|Indent | what character(s) are placed before exception in the log (default is tab)|\nStackTraceIndent | indent between each stack trace line (default is two tab characters)\nBeforeType | is written before exception type name (default [)\nAfterType | is written after exception type name (default ])\nSeparator | separator between exception type and message\nLogStack | to log stack trace or not (for console logger e.g.)\n\n#### how it works\nThe package does not contain any assemlby just a source file.\n\nThis is `IndentExceptionLayoutRenderer.cs` text file.\nIt has `IndentExceptionLayoutRenderer` class defined within `YourNamespace.NLog.Extention` namespace. \n\nAll `.cs` files are copied to text template `.pp` when package is released and nupkg file is created.\nNamespace `YourNamespace` is changed to the current project default namespace value.\n\nThen `.pp` files are injected into every project that references `IndentException` package.\n\n#### how to use\n`Sample` folder contains sample project how package may be consumed.\n\n* Add package to a project\n* create/adjust `nuget.config` file and add `extensions` element referencing your project assembly name\n```\n\t\u003cextensions\u003e\n\t\t\u003cadd assembly=\"YOUR_PROJECT_ASSEMBLY_NAME\"/\u003e\n\t\u003c/extensions\u003e\n```\nInitialize NLog as usually and get exception formatting extention working. \n\n#### console log sample\nHere is console output for layout like `layout=\"${level} ${message}${onexception:${newline}${IndentException:LogStack=false:separator=\u0026#x9;:beforeType=:aftertype=}}\"`\nthere is no stack trace shown (because of `LogStack=false`)\n```\nError tryException failure\n        ArgumentException       outer exception\n        KeyNotFoundException    innerException\nError failed to start NLogTest\n        ArgumentException       bad try\n        ArgumentException       outer exception\n        KeyNotFoundException    innerException\n```\n\n#### file log sample\nBelow you can find file logging sample using layout `layout=\"[${threadid}] ${longdate} ${level} (${logger}) ${message}${onexception:${newline}${IndentException}}`\n\n`outer exception` and `inner exception` stack trace is logged only once. Error type and message are logged only if error processing code tries to log the same exception second time\n\n```\n[1] 2019-01-27 19:56:57.7258 Debug (YourNamespace.NLog.Extention.Test.Program) starting\n[1] 2019-01-27 19:56:57.7769 Error (YourNamespace.NLog.Extention.Test.Classes.UnitOfWork) tryException failure\n\t[ArgumentException] outer exception\n\t\tat YourNamespace.NLog.Extention.Test.Classes.UnitOfWork.outerException()\n\t\tat YourNamespace.NLog.Extention.Test.Classes.UnitOfWork.tryException()\n\t[KeyNotFoundException] innerException\n\t\tat YourNamespace.NLog.Extention.Test.Classes.UnitOfWork.innerException()\n\t\tat YourNamespace.NLog.Extention.Test.Classes.UnitOfWork.outerException()\n[1] 2019-01-27 19:56:57.7769 Error (YourNamespace.NLog.Extention.Test.Program) failed to start NLogTest\n\t[ArgumentException] bad try\n\t\tat YourNamespace.NLog.Extention.Test.Classes.UnitOfWork.tryException()\n\t\tat YourNamespace.NLog.Extention.Test.Program.Main(String[] args)\n\t[ArgumentException] outer exception\n\t[KeyNotFoundException] innerException\n[1] 2019-01-27 19:56:57.8344 Debug (YourNamespace.NLog.Extention.Test.Program) the end\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foleksabor%2Fnlog.indentexception","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foleksabor%2Fnlog.indentexception","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foleksabor%2Fnlog.indentexception/lists"}