Enables contextual information to flow with your code:
usingSystem;usingContextually;namespaceSample{classApp{staticvoidMain(string[]args){// Setup top level context of the entire app.varsystemContext=newNameValueCollection{["MachineName"]=System.Environment.MachineName};using(Relevant.Info(systemContext)){// Shows that the context flows even if you start a new thread.Task.Run(AppMainLoop).Wait();}// This is the end of the context scope.}voidAppMainLoop(){Console.WriteLine("Enter your name:");varuserName=Console.ReadLine();varappContext=newNameValueCollection{["UserName"]=userName};// Setup a sub-context of relevant information.using(Relevant.Info(systemContext)){while(...)DoWork();}// End of the sub-scope. The "UserName" is not// available anymore, but 'MachineName' still is.}voidDoWork(){try{
...}catch(Exceptionex){// Now you can collect all contextual information// from all open scopes and sub-scopes.varaggregatedContext=Relevant.Info();// This helps with analysis of 'dynamic' data,// which is not known at compile time.Logger.LogError(ex,aggregatedContext);}}}}