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.

    16 comments:

    1. 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
    2. 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
    3. 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
    4. Thanks a lot!!! i get your valuable information it really very help full for everyone. keep it up........... helping us.
      Japan VPS server

      ReplyDelete
    5. 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
    6. Wow! Nice post
      If you are searching for the best Domain, Web Hosting. you can select France Dedicated Server Hosting

      ReplyDelete

    7. Thanks for this enlightening blog, its very utilitarian for people like me, Keep sharing these type of didactic blogs. I also want to share some of the best Sweden Dedicated Server Hosting services for your website at a reasonable price.

      ReplyDelete
    8. Your post is too good. This is very unique information for me. fantastic blog post. Thanks for sharing this type of informative blog post. Dubai Dedicated Server Hosting

      ReplyDelete
    9. This blog was very Impressive thank you for this information. If you are looking for the fastest and cheapest dedicated Hosting then buySpain Dedicated Server you can ask us for more details and services.

      ReplyDelete
    10. Amazing blog
      your post is mindblowing, This is literally a superb post Thank you for such great help and guidance. This blog is really helpful and useful. If you want to get more, complete and cheapest Canada Dedicated Server Hosting

      ReplyDelete
    11. This comment has been removed by the author.

      ReplyDelete
    12. Very useful information about ''DataObjects.Net 5.0 meets NLog & log4net''. all information is very good. I like this blog. If you want to get the best and cheap Ukraine Dedicated Server you visit this. you can ask us for more details.
      Thank you

      ReplyDelete
    13. Your article is really very creative. you post all the useful things. If you are interested to know server hosting then choose UK Dedicated Server with Online Server. It offers hassle-free web hosting solutions worldwide

      ReplyDelete
    14. kinds of this blog thanks for sharing !
      I am very inspire. and I hope will keep bringing blogs like this.
      India Dedicated Server Hosting India Dedicated Server Hosting

      ReplyDelete
    15. I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. 스포츠토토탑

      ReplyDelete
    16. I admire his knowledge and goods, but I'd want to add my two cents. First and foremost, I lack a comparison matrix. However, because it has a lower learning curve, I still recommend LLBLgenpro. Thoma's Entity Broker, in my opinion, has more functionality, but it is also more difficult to use. And, if you're anything like me, you need answers immediately... Using an O/R mapper should be a simple and quick process that requires little learning time and maximizes efficiency. When the requirements indicated above are high on your priority list, I believe Frans Bouma's product is superior. You can play Brawl Stars on PC now and is running games.lol safe? YES!

      ReplyDelete