{"action":"created","issue":{"url":"https://api.github.com/repos/serilog/serilog-enrichers-environment/issues/18","repository_url":"https://api.github.com/repos/serilog/serilog-enrichers-environment","labels_url":"https://api.github.com/repos/serilog/serilog-enrichers-environment/issues/18/labels{/name}","comments_url":"https://api.github.com/repos/serilog/serilog-enrichers-environment/issues/18/comments","events_url":"https://api.github.com/repos/serilog/serilog-enrichers-environment/issues/18/events","html_url":"https://github.com/serilog/serilog-enrichers-environment/issues/18","id":250432882,"node_id":"MDU6SXNzdWUyNTA0MzI4ODI=","number":18,"title":"Add support for enricher constructor dependency injection","user":{"login":"osudude","id":7307682,"node_id":"MDQ6VXNlcjczMDc2ODI=","avatar_url":"https://avatars1.githubusercontent.com/u/7307682?v=4","gravatar_id":"","url":"https://api.github.com/users/osudude","html_url":"https://github.com/osudude","followers_url":"https://api.github.com/users/osudude/followers","following_url":"https://api.github.com/users/osudude/following{/other_user}","gists_url":"https://api.github.com/users/osudude/gists{/gist_id}","starred_url":"https://api.github.com/users/osudude/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/osudude/subscriptions","organizations_url":"https://api.github.com/users/osudude/orgs","repos_url":"https://api.github.com/users/osudude/repos","events_url":"https://api.github.com/users/osudude/events{/privacy}","received_events_url":"https://api.github.com/users/osudude/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-08-15T20:44:06Z","updated_at":"2018-06-22T07:57:04Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"In .NET core, Microsoft got rid of good old HttpContext.Current.  You now have to get at it by injecting IHttpContextAccessor into your class constructor that needs to read various http header values.  It would be nice if we could inject IHttpContextAccessor into our constructor for enriching values based upon the current http request context (yes, this is possible via middleware but P.I.T.A.).  Enricher properties of interest would be various request headers and the user name for the current request."},"comment":{"url":"https://api.github.com/repos/serilog/serilog-enrichers-environment/issues/comments/399356428","html_url":"https://github.com/serilog/serilog-enrichers-environment/issues/18#issuecomment-399356428","issue_url":"https://api.github.com/repos/serilog/serilog-enrichers-environment/issues/18","id":399356428,"node_id":"MDEyOklzc3VlQ29tbWVudDM5OTM1NjQyOA==","user":{"login":"fish0185","id":4829842,"node_id":"MDQ6VXNlcjQ4Mjk4NDI=","avatar_url":"https://avatars1.githubusercontent.com/u/4829842?v=4","gravatar_id":"","url":"https://api.github.com/users/fish0185","html_url":"https://github.com/fish0185","followers_url":"https://api.github.com/users/fish0185/followers","following_url":"https://api.github.com/users/fish0185/following{/other_user}","gists_url":"https://api.github.com/users/fish0185/gists{/gist_id}","starred_url":"https://api.github.com/users/fish0185/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fish0185/subscriptions","organizations_url":"https://api.github.com/users/fish0185/orgs","repos_url":"https://api.github.com/users/fish0185/repos","events_url":"https://api.github.com/users/fish0185/events{/privacy}","received_events_url":"https://api.github.com/users/fish0185/received_events","type":"User","site_admin":false},"created_at":"2018-06-22T07:57:04Z","updated_at":"2018-06-22T07:57:04Z","author_association":"NONE","body":"how about inject IServiceCollection\r\n`public class RequestIdEnricher : ILogEventEnricher\r\n    {\r\n        private readonly IHttpContextAccessor _httpContextAccessor;\r\n\r\n        public RequestIdEnricher(IServiceCollection services)\r\n        {\r\n            var sp = services.BuildServiceProvider();\r\n            _httpContextAccessor = sp.GetService<IHttpContextAccessor>();\r\n        }\r\n\r\n        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)\r\n        {\r\n            if (logEvent == null)\r\n            {\r\n                throw new ArgumentNullException(\"logEvent\");\r\n            }\r\n\r\n            string correlationId = _httpContextAccessor?.HttpContext?.Request?.Headers[\"CorrelationId\"];\r\n\r\n            if (string.IsNullOrWhiteSpace(correlationId))\r\n            {\r\n                return;\r\n            }\r\n\r\n            var correlationIdProperty = new LogEventProperty(\"CorrelationId\", new ScalarValue(correlationId));\r\n            logEvent.AddPropertyIfAbsent(correlationIdProperty);\r\n        }\r\n    }`"}}
{"actor":{"display_login":"fish0185"}}