peter
peter

Reputation: 2103

Log to database with EF Code First

I would like to have log4net log to my database. I have added an AdoNetAppender as written in the docs . The docs also give the definition for the Log-table to create. Since I am using Entity Framework with Code First and I am recreating the database quite often (DropCreateDatabaseAlways) during development, I don't want to manually create the table. I tried to create a class Log instead that matches the definition in the docs.

public class Log
{
    public int Id { get; set; }
    public DateTime Date { get; set; }
    public string Thread { get; set; }
    public string Level { get; set; }
    public string Logger { get; set; }
    public string Message { get; set; }
    public string Exception { get; set; }
}

However, when using the AdoNetAppender I get an error that seems unrelated

Cannot drop database "aspnet-myDb-20150625044347" because it is currently in use.

but that disappears if I take out the AdoNetAppender.

How can I log to my database with Entity Framework code first? Thank you for any help.

Upvotes: 2

Views: 1440

Answers (1)

workabyte
workabyte

Reputation: 3755

The answer here may solve your problem. The main issue is that the database still has an open connection.

short clip is to use Pooling=false. Being that this is in development you should not need pooling.

I know answers with links are discouraged but this is a link to another SO answer so I think we are safe here.

Hope this helps

Upvotes: 3

Related Questions