Entity Framework 6 error logging in Sqls

Asked

Viewed 44 times

5

I’m trying to see the Sqls run by Entity Framework, use version 6.

I’m following this guide.

I made a new Dbcontext using the graphical interface. 5 tables only.

The code is inside an API2 Web Controller:

public class TAGsController : ApiController
{
    private MEUDB db = new MEUDB();

    // GET: api/TAGs/5
    [Route("{Key}/api/tag/tag/{id}")]
    [ResponseType(typeof(TAG))]
    public async Task<IHttpActionResult> GetTAG(long id)
    {
        db.Database.Log = Console.Write;
        TAG tAG = await db.TAGs.FindAsync(id);
        if (tAG == null)
        {
            return NotFound();
        }

        return Ok(tAG);
    }

}

When debugging I went to the Find line and it returned the following in the output window:

The thread 0x8188 has exited with code 259 (0x103).

What am I doing wrong? According to the guide should just be this.

Edited: More information

By doing everything the same, only by using the Find(), without the Async(), it works.

TAG tAG = await db.TAGs.Find(id);

Is there any extra setting for this? Or some special care?

  • Dude, see if this [link][1] helps you. &#xD; &#xD; &#xD; [1]: http://stackoverflow.com/questions/18887864/what-is-a-thread-exit-code

  • It talks about the debug, even without the debug it continues without logging in. It has to do with Async, using Find without async it works.

1 answer

2


You can log not necessarily in console. It can be done in text file, on Event Viewer, in Trace... how the idea is to pass a delegate, to log into text file, you can use:

context.Database.Log = mensagem => File.AppendText("C:\\meuarquivodelog.txt").WriteLine(mensagem);
  • 1

    I did what you talked to log4net, it worked normal, same idea to pass the Gate. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.