{"action":"created","issue":{"url":"https://api.github.com/repos/serilog/serilog/issues/633","repository_url":"https://api.github.com/repos/serilog/serilog","labels_url":"https://api.github.com/repos/serilog/serilog/issues/633/labels{/name}","comments_url":"https://api.github.com/repos/serilog/serilog/issues/633/comments","events_url":"https://api.github.com/repos/serilog/serilog/issues/633/events","html_url":"https://github.com/serilog/serilog/issues/633","id":126389178,"number":633,"title":"Add batching/thread offloading to many sinks ","user":{"login":"DmitryNaumov","id":866389,"avatar_url":"https://avatars.githubusercontent.com/u/866389?v=3","gravatar_id":"","url":"https://api.github.com/users/DmitryNaumov","html_url":"https://github.com/DmitryNaumov","followers_url":"https://api.github.com/users/DmitryNaumov/followers","following_url":"https://api.github.com/users/DmitryNaumov/following{/other_user}","gists_url":"https://api.github.com/users/DmitryNaumov/gists{/gist_id}","starred_url":"https://api.github.com/users/DmitryNaumov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DmitryNaumov/subscriptions","organizations_url":"https://api.github.com/users/DmitryNaumov/orgs","repos_url":"https://api.github.com/users/DmitryNaumov/repos","events_url":"https://api.github.com/users/DmitryNaumov/events{/privacy}","received_events_url":"https://api.github.com/users/DmitryNaumov/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/serilog/serilog/labels/discussion","name":"discussion","color":"bfe5bf"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-01-13T10:33:14Z","updated_at":"2016-03-09T09:24:48Z","closed_at":null,"body":"In multi-threaded environment at least some existing sinks suffer from lot of contentions/blocking. For example, ConsoleSink creates lot of contentions inside BCL (TextWriter.Synchronized is used for Console.Out), same issue with FileSink.\r\n\r\nIt would be nice to support batching and/or background flushing (thread offloading) capability in many of them. But of course it makes no sense to re-invent this wheel in every sink.\r\n\r\nIf you agree this whole idea worth further discussion, let me write few more sentences to describe my idea:\r\nwe do have PeriodicBatchingSink which does exactly what I need. What if using PBS + delegation we can add background flushing to any sink. So calls to Emit actually will be queued in PBS and only when timer fires buffered events will be emitted into original sink in background thread.\r\n\r\nThis is about background flushing, batching requires changes in ILogEventSink.Emit signature or (which is much better) introducing another interface. As a major and visible change it can be done later."},"comment":{"url":"https://api.github.com/repos/serilog/serilog/issues/comments/194201872","html_url":"https://github.com/serilog/serilog/issues/633#issuecomment-194201872","issue_url":"https://api.github.com/repos/serilog/serilog/issues/633","id":194201872,"user":{"login":"DmitryNaumov","id":866389,"avatar_url":"https://avatars.githubusercontent.com/u/866389?v=3","gravatar_id":"","url":"https://api.github.com/users/DmitryNaumov","html_url":"https://github.com/DmitryNaumov","followers_url":"https://api.github.com/users/DmitryNaumov/followers","following_url":"https://api.github.com/users/DmitryNaumov/following{/other_user}","gists_url":"https://api.github.com/users/DmitryNaumov/gists{/gist_id}","starred_url":"https://api.github.com/users/DmitryNaumov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DmitryNaumov/subscriptions","organizations_url":"https://api.github.com/users/DmitryNaumov/orgs","repos_url":"https://api.github.com/users/DmitryNaumov/repos","events_url":"https://api.github.com/users/DmitryNaumov/events{/privacy}","received_events_url":"https://api.github.com/users/DmitryNaumov/received_events","type":"User","site_admin":false},"created_at":"2016-03-09T09:24:48Z","updated_at":"2016-03-09T09:24:48Z","body":"@nblumhardt I've committed preliminary code in my [repo](https://github.com/DmitryNaumov/serilog/commit/2106f15bddccc289f24ad36baf13ed6e021cd40d) to give some food for discussion. Questions are:\r\n\r\n-  Configuration. Extension method WriteAsyncTo doesn't please my eyes. But Logger(Sink)Configuration are doing great job incapsulating their state. 'Internal' doesn't work because configuration and sinks are in different assemblies. Any help/suggestions/ideas are welcome.\r\n\r\n- Sink batching support. Imo, sinks should support batches on their lowest level. Otherwise writing to file or network wouldn't be as effective as it can be. It can be done via adding to ILogEventSink, but it breaks contract, deriving from it or adding brand new separate interface for it. Want to hear your opinion.\r\n\r\n- Imo makes no sense to have both PeriodicBatchingSink and DelegatingPeriodicBatchingSink. Delegation should be implemented out-of-the-box. Existing sinks like Seq should not derived from PBS, but be implemented in sync-way and use delegating capabilities of PBS or DBPS (which one will survive). It would keep async things in one place and simplifies sink development.\r\n\r\n- PBS.EmitBatchAsync. Didn't understand why declare async contract to be called and waited from timer's thread? We're already 'in background', it just complicates things imo.\r\n\r\n- And last (but I think I forget something) but not the least - can I use any mock library for tests?\r\n\r\nPlease share your thoughts on these issues, may be you totally disagree with idea of built-in async support."}}