Setting Transaction ID in Logs
CADP for .NET Core allows you to set transaction IDs for APIs in log entries to enhance the readability of logs. You can set the value of the transaction ID in the TransactionID
property available in the LoggerWrapper
class.
The TransactionID
should be of string type.
LoggerWrapper.TransactionID = <value of transaction id>;
Example 1
LoggerWrapper.TransactionID = "a1b1c1-a2b2c2";
var session = new NaeSession(<username>, <password>, <propertyFilePath>);
In the above code, the value of transaction id for NaeSession creation is set to "a1b1c1-a2b2c2"
.
Sample logs
[Fri Nov 10 2023 15:20:54.912 61420:1][TransactionID:a1b1c1-a2b2c2] - Information: Sessions.ConfigLoader.ReadConfig: CADP .Net Core v 8.13.0.0 Started.
[Fri Nov 10 2023 15:20:54.926 61420:1][TransactionID:a1b1c1-a2b2c2] - Debug: Sessions.ConfigLoader.ReadConfig: - Enter
...............
...............
[Fri Nov 10 2023 15:20:56.087 61420:1][TransactionID:a1b1c1-a2b2c2] - Debug: Sessions.NaeSession.Login: - Exit
[Fri Nov 10 2023 15:20:56.088 61420:1][TransactionID:a1b1c1-a2b2c2] - Information: Sessions.NaeSession.CreateNaeSession: NaeSession created successfully.
Example 2
LoggerWrapper.TransactionID = "a3b3c3-a4b4c4";
byte[] encData = gcm.Encrypt(nonce, inputBytes, out tag, Encoding.ASCII.GetBytes(Default_AAD));
In the above code, the value of transaction id for the Encrypt API is set to "a3b3c3-a4b4c4"
.
Sample logs
[Thu Nov 09 2023 14:49:47.698 57408:1][TransactionID:a3b3c3-a4b4c4] - Debug: Crypto.NaeAesGcmKey.Encrypt: - Enter
[Thu Nov 09 2023 14:49:47.699 57408:1][TransactionID:a3b3c3-a4b4c4] - Debug: Remote.RemoteAesGcm.Encrypt: - Enter
...............
...............
[Thu Nov 09 2023 14:49:49.834 57408:1][TransactionID:a3b3c3-a4b4c4] - Debug: Remote.RemoteAesGcm.Encrypt: - Exit
[Thu Nov 09 2023 14:49:49.835 57408:1][TransactionID:a3b3c3-a4b4c4] - Debug: Crypto.NaeAesGcmKey.Encrypt: - Exit
Note
To remove the existing TransactionID, set the value of TransactionID to
""
orstring.Empty
.Once, a TransactionID is set for any API, the same TransactionID continues to apply to the next APIs if not set explicitly. If you don't want to continue with the same value, either set the TransactionID to any specific value or to
""
orstring.Empty
if TransactionID is not needed.