Session less Cobalt Logging

Is it possible to use Cobalt Logging for applications without web sessions? This is for an existing Windows service app that wants to use Cobalt Logging.

Best Answer

  • It is possible, and we do this in the Cayman project. Since there is no http context (or request headers), you have to setup the RequestValues object yourself. RequestValues is a ThreadStatic object. We are able to chain vertical calls together by passing values via Coherence, and then setting the values when our execution thread starts. **requestContext** is the object that is passed from coherence and unique to our implementation. > RequestValues.setTransactionGUID(Guid.NewGuid().ToString("N")); > RequestValues.setParentGUID(requestContext.TransactionGuid); > RequestValues.setRootGUID(requestContext.RootGuid); > RequestValues.setSessionID(requestContext.SessionId); > RequestValues.setUserGUID(requestContext.UserGuid); > RequestValues.setBusinessUnit(this.productSettings.BusinessUnit); > RequestValues.setProduct(this.productSettings.ProductName); Once RequestValues has been setup, calls to ApplicationLogger will write out the correct values to tremor and ErrorGui. This also assumes that you have your log4net or log4j xml file correct with the correct appenders. Remember RequestValues is ThreadStatic, so if you have multiple threads you have to manage and copy the values between threads. We don't do this in the Cayman windows service since each thread is unique and needs its own RequestValues.