News, examples, tips, ideas and plans.
Thoughts around ORM, .NET and SQL databases.

Wednesday, March 05, 2014

DataObjects.Net 5.0 built-in logging

Yeah, we have to admit it - logging in DataObjects.Net 4.x was implemented quite odd and its API was not clear even to some of product developers, not to mention customers who were wondering whether the bloody logging works at all and how the hell it is supposed to be configured. Finally, these days are gone and starting from DataObjects.Net 5.0 we re-implemented the logging.

So, what has changed? The answer is - almost all, including inconsistent loggers' names, tricky xml configuration and peculiar log formats. Imho, the best characteristic for the new logging will be "brain-dead obvious" "extremely simple".

OK, let's dive into the details.

Loggers

These are named logs that record messages from specific parts of DataObjects.Net. There are 4 of them:


  • Xtensive.Orm - logs Session & Transaction-related events and exceptions.
  • Xtensive.Orm.Building - logs events during the Domain building process.
  • Xtensive.Orm.Sql - logs SQL statements sent to database server.
  • Xtensive.Orm.Upgrade - logs events during database schema upgrade.

  • Log writers


  • Console - writes messages to application's console window, if any. Useful for small & test projects.
  • DebugOnlyConsole - the same as Console but writes log data only when a project is run in Debug mode.
  • path_to_file - appends log messages to a specified file. If file is absent, it will be created. Useful for development & production environments. path_to_file can be either absolute or relative to the application location.
  • None - writes to /dev/null.

  • Configuration

    Configuration of built-in logging is made in application configuration file (app.config or web.config). Logger configuration takes 2 parameters: logger name as source and log writer name as target.

    Example: Logging everything to Console
      <Xtensive.Orm>
        <domains>
          <domain name="Default".../>
        </domains>
    
        <logging>
          <log source="Xtensive.Orm" target="Console"/>
          <log source="Xtensive.Orm.Building" target="Console"/>
          <log source="Xtensive.Orm.Sql" target="Console"/>
          <log source="Xtensive.Orm.Upgrade" target="Console"/>
        </logging>
      </Xtensive.Orm>
    
    
    Example: Logging everything to files
      <Xtensive.Orm>
        <domains>
          <domain name="Default".../>
        </domains>
    
        <logging>
          <log source="Xtensive.Orm" target="C:\Orm.log"/>
          <log source="Xtensive.Orm.Building" target="C:\Orm.Building.log"/>
          <log source="Xtensive.Orm.Sql" target="C:\Orm.Sql.log"/>
          <log source="Xtensive.Orm.Upgrade" target="C:\Orm.Upgrade.log"/>
        </logging>
      </Xtensive.Orm>
    
    

    To simplify things in case you want to write messages from all loggers into the same stream, you may want to use our magic asterisk, like this: Example: Logging everything to a file
      <Xtensive.Orm>
        <domains>
          <domain name="Default".../>
        </domains>
    
        <logging>
          <log source="*" target="C:\Orm.log"/>
        </logging>
      </Xtensive.Orm>
    
    
    In addition to the built-in log writers DataObjects.Net 5 is shipped with 2 extensions allowing to redirect logging output to NLog & log4net. Read about that in the second part.

    2 comments:

    1. Thanks! Good explanation, waiting for more ;-)

      ReplyDelete