Tuesday 15 July 2014

c# - Logging nested distributed function calls with common guid using PostSharp -


At present, each component of multi-level system logs all the function insotations using PostSharp.

For example, an application call for the WCF service can call a data service (in the process) and an audit service (through NSISbis)

  - & gt; CaseService: getCaseWithAppointments () (via WCF) CaseService - & gt; DataService: getCaseById () CaseService - & gt; DataService: getCaseAppointments () CaseService - & gt; AuditService: logCaseAccess () (via NServiceBus)  

As a result, four rows will be written in the logs table, but after seeing the log table later, it is not possible to recognize that the The logCaseAccess () call was called as an integration call getCase () as part of the application call.

It may be four rows, identified as a group

I can see how it will be possible to create a good application, Can be passed as a parameter, but it will not be possible only by changing the signature for every function solution? The solution already includes more than 20 services with more than 200 operations contracts, so it will represent a lot of effort.

Is there a way to modify each of the services, so that each of their functions expects extra parameters (good) and any consistent call (possibly using the limitations of post-city method) To pass?

I have read this (), but unfortunately it was not known of the distributed (and multi-threaded) nature of my requirement:

If you have only synchronous code, then the problem of identifying the call stack in the log is often solved by including the existing thread id in the output, it is usually built in to the underlying logging framework Can be configured in. For example log4net:

  layout type = "log4net.Layout.PatternLayout" & gt; & Lt; Conversion pattern value = "[% thread]% message% newline" / & gt; & Lt; / Layout & gt;  

If you work with async methods, you will need to use the "logical call reference" async methods to have a helpful article about solving the same logging problem. :

You can customize the example in the article for your needs. For example, you can create a OnMethodBoundaryAspect and save the GUID in the call context on the method entry If it is not yet since standard PostSharp Ging calls will not use your custom GUID in context, so you'll need to output logs own aspect.

  [serializable] public class test aspect: OnMathBoundaryExpect {Private cost string name = "log ID"; Public Test Aspect () {this.ApplyToStateMachine = true; } Public Override Zero OnEntry (MethodExecutionArgs args) {Object referenceId = CallContext.LogicalGetData (name); If (contextId == null) {contextId = Guid.NewGuid () ToString (); CallContext.LogicalSetData (name, reference ID); } // Create the log message and send the output to the built-in framework console. WrightLine ("{0}: {1}", Reference ID, Ingress Method.Name); }}  

No comments:

Post a Comment