简体   繁体   English

如何在Dynamics CRM中在插件事务之外执行操作

[英]How to Execute an Operation Outside of a Plugin Transaction in Dynamics CRM

I have a Trace entity in my CRM system, and I want to insert records for that entity regardless of whether or not a plugin or workflow activity fails. 我的CRM系统中有一个Trace实体,并且无论插件或工作流活动是否失败,我都希望为该实体插入记录。 When real-time plugin/workflow fails, all the data operations that have happened are rolled back, so any inserted Trace records are also rolled back. 当实时插件/工作流失败时,所有已发生的数据操作都会回滚,因此所有插入的跟踪记录也会回滚。

I know I can use the ITracingService, but there are many times when end users aren't willing/able to relay the issues on to me when an error occurs. 我知道我可以使用ITracingService,但是在很多情况下,最终用户都不愿意/无法在发生错误时将问题转发给我。

Does anyone know of a supported way to have the Trace records get inserted outside of the transaction, so they are available whether or not the code succeeds or fails? 有谁知道将跟踪记录插入事务外部的受支持方式,因此无论代码成功与否,它们都可用?

If you are using Dynamics CRM Online (this is now supported as of the Spring Update.) It works great and automatically clears the log after 1 day. 如果您使用的是Dynamics CRM Online(从Spring Update开始支持此功能。)它可以很好地工作,并在1天后自动清除日志。

For on-premises, you have to write them outside of the executing transaction. 对于本地,您必须在执行事务之外编写它们。 So, you have a few different options: 因此,您有几种不同的选择:

  1. Create a new connection to Dynamics CRM using stored credentials (store them in a custom entity or the Plugin Step's Unsecure or Secure Configuration String (recommend you encrypt the password whichever option you choose.) 使用存储的凭据创建与Dynamics CRM的新连接(将它们存储在自定义实体或插件步骤的“不安全”或“安全配置字符串”中(建议您对密码进行加密)。

  2. Use a tool such as NLog (or Log4Net) and log the same as any other .NET application (since online & sandbox are not a limitation.) 使用诸如NLog(或Log4Net)之类的工具,并与任何其他.NET应用程序进行日志记录(因为在线和沙箱不受限制)。

  3. Roll your own custom logging solution and write to either disk or a webservice. 滚动您自己的自定义日志记录解决方案,然后写入磁盘或Web服务。 Make it implement ITracingService (it just has one simple method) and it can be used anywhere you might use CRM's tracing implementation. 使它实现ITracingService (它只有一种简单的方法),并且可以在可能使用CRM的跟踪实现的任何地方使用。 You can see my quick implementation (for a different purpose) here: https://stackoverflow.com/a/28186429/394978 . 您可以在这里查看我的快速实现(出于不同目的): https : //stackoverflow.com/a/28186429/394978 You'll still need to implement the writing to disk/webservice/sql. 您仍然需要实现对disk / webservice / sql的写入。 Btw, make it write to a web service and technically it could still work in CRM Online. 顺便说一句,使其写入Web服务,从技术上讲,它仍然可以在CRM Online中使用。

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

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