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

Monday, March 17, 2014

DataObjects.Net 5.0 meets NLog & log4net

In the previous post we explained DataObjects.Net built-in logging capabilities. Now it is time to show how popular logging libraries like log4net and NLog can be integrated with it.

We would need the list of names of built-in logs:


  • 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.

  • log4net

    1. Add DataObjects.Net logging provider for log4net. It will automatically add log4net.
    2. Set up log provider in Xtensive.Orm configuration section

       <Xtensive.Orm>
         <domains>
           <domain ... >
           </domain>
         </domains>
         <logging provider="Xtensive.Orm.Logging.log4net.LogProvider, Xtensive.Orm.Logging.log4net">
       </Xtensive.Orm>
      
    3. Configure log4net. Use the above-mentioned loggers' names, e.g.:

       <?xml version="1.0" encoding="utf-8" ?>
       <configuration>
         <configSections>
           ...
           <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
         </configSections>
       
         <log4net>
           <appender name="ConsoleAppernder" type="log4net.Appender.ConsoleAppender">
             <layout type="log4net.Layout.PatternLayout">
               <conversionPattern value="%date [%thread] %-5level %logger %message%newline" />
             </layout>
           </appender>
         
           <logger name="Xtensive.Orm">
             <level value="ALL" />
             <appender-ref ref="ConsoleAppernder" />
           </logger>
         </log4net>
       </configuration>
      
      

    NLog

    1. Add DataObjects.Net logging provider for NLog. It will automatically add NLog.
    2. Set up log provider in Xtensive.Orm configuration section

       <Xtensive.Orm>
         <domains>
           <domain ... >
           </domain>
         </domains>
         <logging provider="Xtensive.Orm.Logging.NLog.LogProvider, Xtensive.Orm.Logging.NLog">
       </Xtensive.Orm>
      
    3. Configure NLog. Use the above-mentioned loggers' names, e.g.:

          <?xml version="1.0" encoding="utf-8" ?>
          <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      
            <targets>
              <target name="console" xsi:type="Console" />
            </targets>
      
            <rules>
              <logger name="Xtensive.Orm" minlevel="Debug" writeTo="console" />
            </rules>
          </nlog>
      


    Pretty simple, huh? You can even write your own log provider with ease. Just take a look at the implementation of these two in DataObjects.Net Extensions repository, default branch.

    11 comments:

    1. Best windows hosting india have their own benefits and disadvantages. Understanding the advantages and minuses about them could assist you to choose between them. Windows is actually known for predictable achievement, and Microsoft provides continual auto updates to web hosting providers and computer customers.

      ReplyDelete
    2. When you are choosing a best web hosting company in jaipur, it is important so as to you rely on more than just one or two pieces of suggestion on a recommendation. Many recommendations are from customer who hasn’t even experienced the web hosting company that they are recommending.

      ReplyDelete
    3. There are many cheap dedicated server hosting companies in india, But serverwala.org. a startup is very reliable among them.

      ReplyDelete
    4. Hi, thank you very much for the great information, I learned something new. Very well written. It was so good to read and useful to improve knowledge. Keep posting. I would like to tell you that Onlive Server offers the best and cheapest VPS Server, dedicated server hosting, and web hosting services with amazing features. Apart from that your blog is awesome.
      France VPS Server

      ReplyDelete
    5. Allegedly, your post is mindblowing, This is literally a superb post Thank you for such great help and guidance. You made something impossible possible.
      Thanks, thanks to a lotttttttt!!!!…
      Finland VPS Server

      ReplyDelete
    6. Such a Mindblowing Post that You have shared here, This is an amazing superb article Keep Sharing this...
      Thanks thanks a lotttttttt!!!!

      India VPS Hosting

      ReplyDelete
    7. Thanks a lot!!! i get your valuable information it really very help full for everyone. keep it up........... helping us.
      Japan VPS server

      ReplyDelete
    8. Great Article… I love to read your articles because your writing style is too good, it is very helpful for all of us and I never get bored while reading your article. Visit Germany VPS Hosting

      ReplyDelete
    9. Thanks for sharing your ideas and view, this is appreciable.
      South Korea VPS Hosting

      ReplyDelete
    10. As you are providing information about DataObjects.Net 5.0 meets NLog & log4net. that is extremely good for everyone. Basically, we want to say that your knowledge really impressive that should be spread all over the world. Basically, We are leading server hosting Company. There are lots of companies available in the market that provides the hosting solution. if you want any other information about server hosting Contact us without any hesitation. Onlive Server and Onlive Infotech here are available multiple types of server hosting solutions. for more information Click here - USA VPS Hosting.

      ReplyDelete
    11. There are many blogs I have read But when I read Your Blogs I have found such useful information, fresh content with such amazing editing everything is superb in your blog, Thank you so much for sharing this useful and informative information with us.

      Cybonetic Technologies is a leading web hosting company in Patna offering Fast and Reliable Web Hosting. Buy a domain and hosting at the cheap prices with 24x7 support.
      web hosting company in patna

      ReplyDelete