Özgür Adem Işıklı Özgür Adem Işıklı Software Developer Resume Contact

Software Developer

#11 - Entity Framework Query Logging

In case I forget later, this is a simple note for me.

Introduction

Although Entity Framework is not my favorite ORM library, I have to use it when I develop a .Net application. This is a quick note about how can you create a logging with the queries created by EF.

Example


using System;
using System.Collections.Generic;
using System.Reflection;

namespace ConsoleApplication
{

    public class LogHandler
    {

        public void Write(string content)
        {
            // do something you want
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            MyDBContext db = new MyDBContext();
            // You can send logs to console
            db.Database.Log = Console.Write;    

            // Or you can use a log handler object.
            LogHandler logger = new LogHandler();
            db.Database.Log = logger.Write;
        }

    }
}

What About Comments?

I do not use any comment system such as Disqus because of user's privacy. If you want to discuss something about this post, you may open an issue on the repo.

You may check what is the problem with Disqus;