title: Library Message Handling
body: <p>I am building a library which can parse complex files into a datamodel. Inside the library during parsing and during some other operations on the data structure I am building certain messages might occur (info, warnings, errors).</p>
  
  <p>I need a way for the user of the library to fetch those messages. All stuff I am thinking about boils down to some static Event or a static list of those messages. But I want each object of the datastructure to have its own message queue.</p>
  
  <p>An example:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          CalibData cd1 = new CalibData();
          cd1.LoadFile(@"C:\tmp\file.ext");
          var messageList = cd1.GetMessages();
          cd1.DoOtherStuff();
  
  
          CalibData cd2 = new CalibData();
          cd2.LoadFile(@"C:\tmp\file2.ext");
          cd2.LoadFile(@"C:\tmp\file3.ext2");
  
          messageList = cd1.GetMessages(); //Do other stuff could have produced new Messages
          var messageList2 = cd2.GetMessages();
  
      }
  }
  </code></pre>
  
  <p>Do you have any suggestions on how to implement such behavoir? I need something which is globally accessibly inside each instance, but each instance has another global messenger.</p>
  
  <p>Additional Information:
  Internall I am using an ANTLR Parser which generates a lot of objects (50.000+). Once the datastructure is created a lot of crossreferences are being set on the objects, etc. My main problem is, that I either have to create a static member to handle this, or from LoadFile() pass a messenger very deep into my function calls of the parser, cross referencing etc. In my opionion both is a rather bad choice. Changing the design is not an option since there is more to my problem. The datastructure is stored in 2 files (1 file = description, other file = data). So I can call something like</p>
  
  <pre><code>CalibData cd = new CalibData();
  cd.LoadFile("description file"); //after this call the datastructure is built, but it hasn't got any value data yet
  cd.LoadFile("data file") //now the structure also has value data
  cd.ClearData();
  cd.LoadFile("yet another data file"); //same structure different data
  </code></pre>