{"action":"created","comment":{"url":"https://api.github.com/repos/serilog/serilog/pulls/comments/58621850","id":58621850,"diff_hunk":"@@ -0,0 +1,116 @@\n+// Copyright 2013-2015 Serilog Contributors\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//     http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+using System;\n+using System.Collections.Generic;\n+using System.IO;\n+\n+using Serilog.Events;\n+using Serilog.Parsing;\n+\n+namespace Serilog.Formatting.Display\n+{\n+    // allows for the specific handling of the {Level} element.\n+    // can now have a fixed width applied to it, as well as casing rules.\n+    internal class LogEventLevelValue : LogEventPropertyValue\n+    {\n+        private readonly LogEventLevel _value;\n+\n+        // Assumes reading from Dictionary<,> is thread-safe after construction\n+        private static readonly Dictionary<LogEventLevel, string[]> _shortenedLevelMap\n+            = new Dictionary<LogEventLevel, string[]>\n+                  {\n+                      { LogEventLevel.Verbose, new []{ \"V\", \"Vb\", \"Vrb\", \"Verb\" } },\n+                      { LogEventLevel.Debug, new []{ \"D\", \"De\", \"Dbg\", \"Dbug\" } },\n+                      { LogEventLevel.Information, new []{ \"I\", \"In\", \"Inf\", \"Info\" } },\n+                      { LogEventLevel.Warning, new []{ \"W\", \"Wn\", \"Wrn\", \"Warn\" } },\n+                      { LogEventLevel.Error, new []{ \"E\", \"Er\", \"Err\", \"Eror\" } },\n+                      { LogEventLevel.Fatal, new []{ \"F\", \"Fa\", \"Ftl\", \"Fatl\" } },\n+                  };\n+\n+        public LogEventLevelValue(\n+            LogEventLevel value)\n+        {\n+            _value = value;\n+        }\n+\n+        /// <summary>\n+        /// This method will apply only upper or lower case formatting, not fixed width\n+        /// </summary>\n+        public override void Render(\n+            TextWriter output, \n+            string format = null, \n+            IFormatProvider formatProvider = null)\n+        {\n+            ApplyFormatting(output, _value.ToString(), null, format);\n+        }\n+\n+        /// <summary>\n+        /// Will apply fixed width rules using the provided alignment\n+        /// </summary>\n+        public void Render(\n+            TextWriter output,\n+            Alignment? alignment,\n+            string format = null,\n+            IFormatProvider formatProvider = null)\n+        {\n+            ApplyFormatting(output, AlignedValue(alignment), alignment, format);\n+        }\n+\n+        private string AlignedValue(Alignment? alignment)\n+        {\n+            if (!alignment.HasValue || alignment.Value.Width <= 0)\n+            {\n+                return _value.ToString();\n+            }\n+\n+            if (_value.ToString().Length == alignment.Value.Width)\n+            {\n+                return _value.ToString();\n+            }\n+\n+            if (IsCustomWidthSupported(alignment.Value.Width))\n+            {\n+                return ShortLevelFor(_value, alignment.Value);\n+            }\n+\n+            if (IsOutputStringTooWide(alignment.Value, _value.ToString()))","path":"src/Serilog/Formatting/Display/LogEventLevelValue.cs","position":88,"original_position":88,"commit_id":"023d57c282dcb5ddedee9401c68743a713fa0c8c","original_commit_id":"023d57c282dcb5ddedee9401c68743a713fa0c8c","user":{"login":"nblumhardt","id":342712,"avatar_url":"https://avatars.githubusercontent.com/u/342712?v=3","gravatar_id":"","url":"https://api.github.com/users/nblumhardt","html_url":"https://github.com/nblumhardt","followers_url":"https://api.github.com/users/nblumhardt/followers","following_url":"https://api.github.com/users/nblumhardt/following{/other_user}","gists_url":"https://api.github.com/users/nblumhardt/gists{/gist_id}","starred_url":"https://api.github.com/users/nblumhardt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nblumhardt/subscriptions","organizations_url":"https://api.github.com/users/nblumhardt/orgs","repos_url":"https://api.github.com/users/nblumhardt/repos","events_url":"https://api.github.com/users/nblumhardt/events{/privacy}","received_events_url":"https://api.github.com/users/nblumhardt/received_events","type":"User","site_admin":false},"body":"Adding:\r\n\r\n```csharp\r\nvar stringValue = _value.ToString();\r\n```\r\n\r\non the line above and then using it in all of the subsequent places `_value.ToString()` is used will reduce the number of calls required.\r\n","created_at":"2016-04-05T22:08:12Z","updated_at":"2016-04-05T22:08:12Z","html_url":"https://github.com/serilog/serilog/pull/711#discussion_r58621850","pull_request_url":"https://api.github.com/repos/serilog/serilog/pulls/711","_links":{"self":{"href":"https://api.github.com/repos/serilog/serilog/pulls/comments/58621850"},"html":{"href":"https://github.com/serilog/serilog/pull/711#discussion_r58621850"},"pull_request":{"href":"https://api.github.com/repos/serilog/serilog/pulls/711"}}},"pull_request":{"url":"https://api.github.com/repos/serilog/serilog/pulls/711","id":65196746,"html_url":"https://github.com/serilog/serilog/pull/711","diff_url":"https://github.com/serilog/serilog/pull/711.diff","patch_url":"https://github.com/serilog/serilog/pull/711.patch","issue_url":"https://api.github.com/repos/serilog/serilog/issues/711","number":711,"state":"open","locked":false,"title":"add fixed width functionality for log event output.","user":{"login":"iamkoch","id":792077,"avatar_url":"https://avatars.githubusercontent.com/u/792077?v=3","gravatar_id":"","url":"https://api.github.com/users/iamkoch","html_url":"https://github.com/iamkoch","followers_url":"https://api.github.com/users/iamkoch/followers","following_url":"https://api.github.com/users/iamkoch/following{/other_user}","gists_url":"https://api.github.com/users/iamkoch/gists{/gist_id}","starred_url":"https://api.github.com/users/iamkoch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iamkoch/subscriptions","organizations_url":"https://api.github.com/users/iamkoch/orgs","repos_url":"https://api.github.com/users/iamkoch/repos","events_url":"https://api.github.com/users/iamkoch/events{/privacy}","received_events_url":"https://api.github.com/users/iamkoch/received_events","type":"User","site_admin":false},"body":"#574 Now supports {Level,1} style syntax. Also supports upper/lower variations.","created_at":"2016-04-04T19:09:57Z","updated_at":"2016-04-05T22:08:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"eb1b050eae2b29a7c77c65a69ff8f8a92ab9d2f7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/serilog/serilog/pulls/711/commits","review_comments_url":"https://api.github.com/repos/serilog/serilog/pulls/711/comments","review_comment_url":"https://api.github.com/repos/serilog/serilog/pulls/comments{/number}","comments_url":"https://api.github.com/repos/serilog/serilog/issues/711/comments","statuses_url":"https://api.github.com/repos/serilog/serilog/statuses/023d57c282dcb5ddedee9401c68743a713fa0c8c","head":{"label":"iamkoch:pre-dev","ref":"pre-dev","sha":"023d57c282dcb5ddedee9401c68743a713fa0c8c","user":{"login":"iamkoch","id":792077,"avatar_url":"https://avatars.githubusercontent.com/u/792077?v=3","gravatar_id":"","url":"https://api.github.com/users/iamkoch","html_url":"https://github.com/iamkoch","followers_url":"https://api.github.com/users/iamkoch/followers","following_url":"https://api.github.com/users/iamkoch/following{/other_user}","gists_url":"https://api.github.com/users/iamkoch/gists{/gist_id}","starred_url":"https://api.github.com/users/iamkoch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iamkoch/subscriptions","organizations_url":"https://api.github.com/users/iamkoch/orgs","repos_url":"https://api.github.com/users/iamkoch/repos","events_url":"https://api.github.com/users/iamkoch/events{/privacy}","received_events_url":"https://api.github.com/users/iamkoch/received_events","type":"User","site_admin":false},"repo":{"id":45899705,"name":"serilog","full_name":"iamkoch/serilog","owner":{"login":"iamkoch","id":792077,"avatar_url":"https://avatars.githubusercontent.com/u/792077?v=3","gravatar_id":"","url":"https://api.github.com/users/iamkoch","html_url":"https://github.com/iamkoch","followers_url":"https://api.github.com/users/iamkoch/followers","following_url":"https://api.github.com/users/iamkoch/following{/other_user}","gists_url":"https://api.github.com/users/iamkoch/gists{/gist_id}","starred_url":"https://api.github.com/users/iamkoch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iamkoch/subscriptions","organizations_url":"https://api.github.com/users/iamkoch/orgs","repos_url":"https://api.github.com/users/iamkoch/repos","events_url":"https://api.github.com/users/iamkoch/events{/privacy}","received_events_url":"https://api.github.com/users/iamkoch/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/iamkoch/serilog","description":"Simple .NET logging with fully-structured events","fork":true,"url":"https://api.github.com/repos/iamkoch/serilog","forks_url":"https://api.github.com/repos/iamkoch/serilog/forks","keys_url":"https://api.github.com/repos/iamkoch/serilog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/iamkoch/serilog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/iamkoch/serilog/teams","hooks_url":"https://api.github.com/repos/iamkoch/serilog/hooks","issue_events_url":"https://api.github.com/repos/iamkoch/serilog/issues/events{/number}","events_url":"https://api.github.com/repos/iamkoch/serilog/events","assignees_url":"https://api.github.com/repos/iamkoch/serilog/assignees{/user}","branches_url":"https://api.github.com/repos/iamkoch/serilog/branches{/branch}","tags_url":"https://api.github.com/repos/iamkoch/serilog/tags","blobs_url":"https://api.github.com/repos/iamkoch/serilog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/iamkoch/serilog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/iamkoch/serilog/git/refs{/sha}","trees_url":"https://api.github.com/repos/iamkoch/serilog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/iamkoch/serilog/statuses/{sha}","languages_url":"https://api.github.com/repos/iamkoch/serilog/languages","stargazers_url":"https://api.github.com/repos/iamkoch/serilog/stargazers","contributors_url":"https://api.github.com/repos/iamkoch/serilog/contributors","subscribers_url":"https://api.github.com/repos/iamkoch/serilog/subscribers","subscription_url":"https://api.github.com/repos/iamkoch/serilog/subscription","commits_url":"https://api.github.com/repos/iamkoch/serilog/commits{/sha}","git_commits_url":"https://api.github.com/repos/iamkoch/serilog/git/commits{/sha}","comments_url":"https://api.github.com/repos/iamkoch/serilog/comments{/number}","issue_comment_url":"https://api.github.com/repos/iamkoch/serilog/issues/comments{/number}","contents_url":"https://api.github.com/repos/iamkoch/serilog/contents/{+path}","compare_url":"https://api.github.com/repos/iamkoch/serilog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/iamkoch/serilog/merges","archive_url":"https://api.github.com/repos/iamkoch/serilog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/iamkoch/serilog/downloads","issues_url":"https://api.github.com/repos/iamkoch/serilog/issues{/number}","pulls_url":"https://api.github.com/repos/iamkoch/serilog/pulls{/number}","milestones_url":"https://api.github.com/repos/iamkoch/serilog/milestones{/number}","notifications_url":"https://api.github.com/repos/iamkoch/serilog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/iamkoch/serilog/labels{/name}","releases_url":"https://api.github.com/repos/iamkoch/serilog/releases{/id}","deployments_url":"https://api.github.com/repos/iamkoch/serilog/deployments","created_at":"2015-11-10T08:55:23Z","updated_at":"2015-11-10T08:55:27Z","pushed_at":"2016-04-05T07:22:26Z","git_url":"git://github.com/iamkoch/serilog.git","ssh_url":"git@github.com:iamkoch/serilog.git","clone_url":"https://github.com/iamkoch/serilog.git","svn_url":"https://github.com/iamkoch/serilog","homepage":"http://serilog.net","size":74813,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"serilog:dev","ref":"dev","sha":"e0e0ca8a07e2db2bb8a461e191296181bd62ecbc","user":{"login":"serilog","id":5691010,"avatar_url":"https://avatars.githubusercontent.com/u/5691010?v=3","gravatar_id":"","url":"https://api.github.com/users/serilog","html_url":"https://github.com/serilog","followers_url":"https://api.github.com/users/serilog/followers","following_url":"https://api.github.com/users/serilog/following{/other_user}","gists_url":"https://api.github.com/users/serilog/gists{/gist_id}","starred_url":"https://api.github.com/users/serilog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/serilog/subscriptions","organizations_url":"https://api.github.com/users/serilog/orgs","repos_url":"https://api.github.com/users/serilog/repos","events_url":"https://api.github.com/users/serilog/events{/privacy}","received_events_url":"https://api.github.com/users/serilog/received_events","type":"Organization","site_admin":false},"repo":{"id":8198511,"name":"serilog","full_name":"serilog/serilog","owner":{"login":"serilog","id":5691010,"avatar_url":"https://avatars.githubusercontent.com/u/5691010?v=3","gravatar_id":"","url":"https://api.github.com/users/serilog","html_url":"https://github.com/serilog","followers_url":"https://api.github.com/users/serilog/followers","following_url":"https://api.github.com/users/serilog/following{/other_user}","gists_url":"https://api.github.com/users/serilog/gists{/gist_id}","starred_url":"https://api.github.com/users/serilog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/serilog/subscriptions","organizations_url":"https://api.github.com/users/serilog/orgs","repos_url":"https://api.github.com/users/serilog/repos","events_url":"https://api.github.com/users/serilog/events{/privacy}","received_events_url":"https://api.github.com/users/serilog/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/serilog/serilog","description":"Simple .NET logging with fully-structured events","fork":false,"url":"https://api.github.com/repos/serilog/serilog","forks_url":"https://api.github.com/repos/serilog/serilog/forks","keys_url":"https://api.github.com/repos/serilog/serilog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/serilog/serilog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/serilog/serilog/teams","hooks_url":"https://api.github.com/repos/serilog/serilog/hooks","issue_events_url":"https://api.github.com/repos/serilog/serilog/issues/events{/number}","events_url":"https://api.github.com/repos/serilog/serilog/events","assignees_url":"https://api.github.com/repos/serilog/serilog/assignees{/user}","branches_url":"https://api.github.com/repos/serilog/serilog/branches{/branch}","tags_url":"https://api.github.com/repos/serilog/serilog/tags","blobs_url":"https://api.github.com/repos/serilog/serilog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/serilog/serilog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/serilog/serilog/git/refs{/sha}","trees_url":"https://api.github.com/repos/serilog/serilog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/serilog/serilog/statuses/{sha}","languages_url":"https://api.github.com/repos/serilog/serilog/languages","stargazers_url":"https://api.github.com/repos/serilog/serilog/stargazers","contributors_url":"https://api.github.com/repos/serilog/serilog/contributors","subscribers_url":"https://api.github.com/repos/serilog/serilog/subscribers","subscription_url":"https://api.github.com/repos/serilog/serilog/subscription","commits_url":"https://api.github.com/repos/serilog/serilog/commits{/sha}","git_commits_url":"https://api.github.com/repos/serilog/serilog/git/commits{/sha}","comments_url":"https://api.github.com/repos/serilog/serilog/comments{/number}","issue_comment_url":"https://api.github.com/repos/serilog/serilog/issues/comments{/number}","contents_url":"https://api.github.com/repos/serilog/serilog/contents/{+path}","compare_url":"https://api.github.com/repos/serilog/serilog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/serilog/serilog/merges","archive_url":"https://api.github.com/repos/serilog/serilog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/serilog/serilog/downloads","issues_url":"https://api.github.com/repos/serilog/serilog/issues{/number}","pulls_url":"https://api.github.com/repos/serilog/serilog/pulls{/number}","milestones_url":"https://api.github.com/repos/serilog/serilog/milestones{/number}","notifications_url":"https://api.github.com/repos/serilog/serilog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/serilog/serilog/labels{/name}","releases_url":"https://api.github.com/repos/serilog/serilog/releases{/id}","deployments_url":"https://api.github.com/repos/serilog/serilog/deployments","created_at":"2013-02-14T11:44:03Z","updated_at":"2016-04-04T22:57:23Z","pushed_at":"2016-04-05T07:22:27Z","git_url":"git://github.com/serilog/serilog.git","ssh_url":"git@github.com:serilog/serilog.git","clone_url":"https://github.com/serilog/serilog.git","svn_url":"https://github.com/serilog/serilog","homepage":"http://serilog.net","size":92748,"stargazers_count":758,"watchers_count":758,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":254,"mirror_url":null,"open_issues_count":35,"forks":254,"open_issues":35,"watchers":758,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/serilog/serilog/pulls/711"},"html":{"href":"https://github.com/serilog/serilog/pull/711"},"issue":{"href":"https://api.github.com/repos/serilog/serilog/issues/711"},"comments":{"href":"https://api.github.com/repos/serilog/serilog/issues/711/comments"},"review_comments":{"href":"https://api.github.com/repos/serilog/serilog/pulls/711/comments"},"review_comment":{"href":"https://api.github.com/repos/serilog/serilog/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/serilog/serilog/pulls/711/commits"},"statuses":{"href":"https://api.github.com/repos/serilog/serilog/statuses/023d57c282dcb5ddedee9401c68743a713fa0c8c"}}}}