I am using Nlog As per requirement I am processing few thousand records in Parallel loop
For each item After multiple operations in specifc order (Pipe Fliter pattern) I want to write specifc records (which are failed to load into datastore) in to a Output folder.
This Output folder is not a {basedir} but a specific to each client so I am using nlog and nlog Variable and assoicated configuration as below to write values into file for multithreaded application.
In Config file
<variable name="outPutFileFullName" value=""/>
<target xsi:type="File" name="OutPutFile" fileName="${mdc:item=outPutFileFullName}"
        layout="${message}"/>
<logger name ="ABC" 
 level="Info" writeTo="OutPutFile"></logger>
In Code
_loggingService.SetMappedDiagnosticsContext("outPutFileFullName", outPutFolderFile);
 Parallel.ForEach(allItems
               itemLine =>
     {
       itemLine.OutPutFileFullName = outPutFolderFile;
       var pipeLine = new PipeLine<TEST>();
       pipeLine.Register(new Operation1<TEST>(_loggingService))
       .Register(new Operation2<TEST>(_loggingService))
     .Register(new Operation3<TEST>(_loggingService))
      .Execute(itemLine);
   });
In operation 3 I have a simple method
 private  void WriteToFileFromObject(Test obj)
 {
   LoggingService.Info(obj.FileLineNumber.ToString());
 }
I am expecting this process to write 100 records but it is only writing 17 records always but not same and not in specific order.
If I change fileName="${mdc:item=outPutFileFullName}"
   in config file to a constant value like fileName="${basedir}/logs/Test.log" then all 100 records are written to file. Any Idea Why?
 
     
    