简体   繁体   English

是否有任何SQL Server Serilog接收器来支持.Net Core

[英]Is there any SQL Server Serilog sink to support .Net Core

I was about to use the existing Serilog's SQL Server sink but I realized that the latest pre-release and stable versions do not support ASP.NET Core. 我本打算使用现有的Serilog的SQL Server接收器,但我意识到最新的预发行版本和稳定版本不支持ASP.NET Core。

Is there an alternative to this sink? 有没有这个水槽的替代品? What am I supposed to do? 我应该做些什么? Should I write a new sink? 我应该写一个新的水槽吗?

I can't tell you what you're supposed do, but I can describe a couple options. 我无法告诉您您该做什么,但是我可以介绍几个选择。 The Sql Server Serilog provider on GitHub would be a better place to ask the question of what they intend to do. GitHub上的Sql Server Serilog提供程序将是一个更好的地方,询问他们打算做什么。

Serilog is indeed on the .Net Core train, as many, many other mainstream .Net projects are. Serilog确实与许多其他主流.Net项目一样,都在.Net Core火车上。 You are correct that as of today, the SQL server sink is .Net 4.5 only. 您是正确的,到目前为止,SQL Server接收器仅是.Net 4.5。 You can: 您可以:

  • Continue developing your ASP.Net Core project, target .Net 4.5 in your project json, build and deploy to windows OS only, but carry on using SQL server sink. 继续开发ASP.Net Core项目,在项目json中以.Net 4.5为目标,仅构建并部署到Windows OS,但使用SQL Server Sink进行。

    Many companies are migrating to .Net Core but targeting .Net 4.xx in order to keep 100% back compatibility with existing packages while the kinks are ironed out in the framework. 许多公司正在迁移到.Net Core,但目标是.Net 4.xx,以便在框架中消除缺陷时保持与现有软件包的100%向下兼容性。 This has been a viable solution for my large scale projects. 对于我的大型项目而言,这是一个可行的解决方案。

  • Target .Net Core, and write your own logging repository layer to manage custom SQL and database log dumping code. 以.Net Core为目标,并编写您自己的日志记录存储库层以管理自定义SQL和数据库日志转储代码。

    If you're in core, this is easier than it sounds, but requires experience with Data Repositories and IoC. 如果您处于核心地位,这比听起来容易,但需要具备数据存储库和IoC的经验。 Any code that needs to dump logs to the database would have to have some sort of "ILoggingRepository". 需要将日志转储到数据库的任何代码都必须具有某种“ ILoggingRepository”。 It does however, duplicate calls to logging methods, in addition to deviation from the ILoggerProvider interfaces in Microsoft.Logging.Abstractions - forgoing the flexibility of log levels and such, unless you decided to re-engineer your own. 但是,除了偏离Microsoft.Logging.Abstractions中的ILoggerProvider接口之外,它确实重复了对日志记录方法的调用-除非您决定重新设计自己的日志,否则放弃了日志级别等的灵活性。 It's a working solution; 这是一个可行的解决方案; I never said it was an elegant one. 我从来没有说过这是一个优雅的。

  • Write your own Serilog sink. 编写自己的Serilog接收器。

I don't have experience with this one, but I have seen code samples that describe details of how to accomplish this. 我没有这个经验,但是我看到了一些代码示例,这些示例描述了如何完成此操作的细节。 The reason I never pursued this option is due to a fear that by the time I finished writing my beastly database sink, the open-source community would rework the Sql Server version into a fully core-compliant and database independent version. 之所以我从未使用过该选项,是因为担心当我写完我的怪兽数据库接收器时,开源社区会将Sql Server版本重新设计为完全兼容内核且独立于数据库的版本。 This would be the most heavy-handed solution, but also the most robust. 这将是最笨拙的解决方案,但也是最可靠的解决方案。

There may be other sinks available for .Net Core, but if you're looking for the SQL server one specifically, then you most likely are working with constraints that prevent using MongoDB sinks and file providers and such. .Net Core可能还有其他可用的接收器,但是如果您正在寻找专门用于SQL Server的SQL Server,则很可能正在使用阻止使用MongoDB接收器和文件提供程序等约束。

The Serilog sink for SQL Server depends on some types not yet in .NET Core. 用于SQL ServerSerilog接收器取决于.NET Core中尚未使用的某些类型。 Work started to refactor the sink and remove the dependencies, but since then, the types in question have been added to the next .NET Core version: 开始重构接收器并删除依赖项的工作,但是从那时起,有问题的类型已添加到下一个.NET Core版本:

https://github.com/dotnet/corefx/pull/12426 https://github.com/dotnet/corefx/pull/12426

Due to this, the Serilog SQL Server sink will most likely remain .NET Framework-only until the next .NET Core/.NET Standard release, after which support will be quick to add. 因此,Serilog SQL Server接收器很可能将仅保留.NET Framework,直到下一个.NET Core / .NET Standard版本为止,此后将快速添加支持。

In the interim, writing a quick implementation of ILogEventSink of your own would be a reasonable way to get unblocked. 在此期间,编写自己的ILogEventSink的快速实现将是一种不受阻碍的合理方法。

I guess the question is not really technical, but rather a philosophical one, then I do not propose an answer, but consideration: 我想这个问题不是真正的技术性问题,而是一个哲学性的问题,那么我不提出答案,而是考虑:

In my humble opinion, Microsoft with its Silverlight killing, UWP orientation and "escape to clouds", admitted defeat of its entire concept of proprietary software development, so liberation of dotnet platform is nothing more than the farewell gift for developers, deceived in their hopes. 在我的拙见中,微软凭借其Silverlight的杀戮,UWP定位和“向云端逃生”,承认其专有软件开发的整个概念遭到了失败,因此解放dotnet平台无非是为开发人员送上的告别礼物,在他们的希望中蒙骗了。

By itself, dotnet ecosystem is very promising, but its future has little to do with the Microsoft products, as it was before. 就其本身而言,dotnet生态系统非常有前途,但是它的未来与以前的Microsoft产品无关。 At least, I hope as a developer who has been working with Microsoft products more then twenty years. 至少,我希望作为一名使用Microsoft产品已有20多年经验的开发人员。 Therefore, common infrastructure libraries that were focused on concrete Microsoft products (I mean MS SQL Server in this current case) are dying now. 因此,专注于具体的Microsoft产品的通用基础结构库(在当前情况下,我指的是MS SQL Server)正在消失。

Therefore, the conclusion is: if you already have long-term project that tightly coupled with SQLServer, maybe it is better to put some efforts to your current logging solution adaptation, otherwise it is better to look for some logging solution, not dependent on MSSQL. 因此,结论是:如果您已经有一个与SQLServer紧密相关的长期项目,也许最好为当前的日志记录解决方案进行一些调整,否则,最好寻找一些不依赖于MSSQL的日志记录解决方案。 Probably it should support different storages via adapters or something like that. 它可能应该通过适配器或类似的东西支持不同的存储。

Try to look at this , they declare Core support in next version, at least this is a live project. 尝试看看这个 ,他们宣称在下一版本的核心支持,至少这是一个活生生的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM