Log4net with Entity Framework 5 and MVC4

Darkloki

So I am starting this new project and want to use Log4net to log to the Database. I am using EF for other things and it connects fine. For some reason L4N is not logging anything but not throwing any errors. Just wondering what step(s) I may be missing, hope someone can point it out. Do I need to "save" to the db somehow? Thanx so much in advance.

My web.config:

<log4net> 
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
  <bufferSize value="100" />
  <connectionType value="System.Data.EntityClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  <connectionString value="data source=myserver;initial catalog=Reporting;integrated security=false;persist security info=True;User ID=myid;Password=mypassword" />
  <commandText value="INSERT INTO [myschema].[Log] ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
  <parameter>
    <parameterName value="@log_date" />
    <dbType value="DateTime" />
    <layout type="log4net.Layout.RawTimeStampLayout" />
  </parameter>
  <parameter>
    <parameterName value="@thread" />
    <dbType value="String" />
    <size value="255" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%thread" />
    </layout>
  </parameter>
  <parameter>
    <parameterName value="@log_level" />
    <dbType value="String" />
    <size value="50" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%level" />
    </layout>
  </parameter>
  <parameter>
    <parameterName value="@logger" />
    <dbType value="String" />
    <size value="255" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%logger" />
    </layout>
  </parameter>
  <parameter>
    <parameterName value="@message" />
    <dbType value="String" />
    <size value="4000" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%message" />
    </layout>
  </parameter>
  <parameter>
    <parameterName value="@exception" />
    <dbType value="String" />
    <size value="2000" />
    <layout type="log4net.Layout.ExceptionLayout" />
  </parameter>
</appender>
<root>
  <level value="Info" />
  <appender-ref ref="LogFileAppender" />
</root>

and my controller:

 ...
 using log4net;
 using System.Reflection;

namespace MyNames.Controllers
{
  public class ClientController : Controller
  {    
     ReportingEntities db = new ReportingEntities();
     private readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

     public ActionResult Index()
     {  
         this.log.Debug("Sample message to log to Db");
         return View();
     }
   }
 }

EDIT: So I made the mods suggested gorilly but still doesnt work. Just happened to check output window and even though I enabled debugging it still shows this .enter image description here. Tried the debugging suggestion from here but no error was thrown.

From my log4net internal debugging file:

log4net: Assembly [DotNetOpenAuth.Core, Version=4.1.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246] Loaded From [C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\bf082a83\4eb20e9a\assembly\dl3\c62a3103\e01aa9f6_fda1cf01\DotNetOpenAuth.Core.dll]
log4net: Assembly [DotNetOpenAuth.Core, Version=4.1.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246] does not have a RepositoryAttribute specified.
log4net: Assembly [DotNetOpenAuth.Core, Version=4.1.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: Creating repository [log4net-default-repository] using type [log4net.Repository.Hierarchy.Hierarchy]
log4net: Shutdown called on Hierarchy [log4net-default-repository]
hunch_hunch

Add this line to Global.asax.cs (in Application_Start()):

log4net.Config.XmlConfigurator.Configure();

Also, you can turn on log4net debugging to help you figure out what's going wrong by adding this line to your Web.config under <appSettings>:

Edit: The below had value="false", but should be value="true".

<add key="log4net.Internal.Debug" value="true"/>

Edit:

You can send log4net's internal debug logging to a file by adding the following to your Web.config (see the official explanation here):

  <system.diagnostics>
    <trace autoflush="true">
      <listeners>
        <add
            name="textWriterTraceListener"
            type="System.Diagnostics.TextWriterTraceListener"
            initializeData="C:\mylogdirectory\log4net_debug.txt" />
      </listeners>
    </trace>
  </system.diagnostics>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

PieChart in mvc4 from Entity Framework

From Dev

Dropdownlist and MVC4 Entity Framework

From Dev

List of users that not yet in any role, (MVC4 with SimpleMembership and entity framework 5)

From Dev

How can i create a Partial View for MVC4 or MVC 5 using Entity Framework (.edmx Model) with Razor Views?

From Dev

How to mock method with ViewModel in MVC4 with Entity Framework 4.0

From Dev

Will Orchard CMS support MVC4 with Entity Framework

From Dev

MVC4 Entity Framework Controller Database Issue

From Dev

MVC4 app - how to remove Entity Framework and implement SimpleMembershipProvider?

From Dev

How to mock method with ViewModel in MVC4 with Entity Framework 4.0

From Dev

MVC4 Entity Framework 6 Model State Validation Issues

From Dev

.NET Membership in ASP.NET MVC4 and Entity Framework with Oracle as Db

From Dev

Update entity in mvc4

From Dev

Entity Framework profiler - ASP.NET MVC4 with EF 6 -Unable to determine the provider name

From Dev

How to retrieve image from database without using Entity Framework in ASP.NET MVC4

From Dev

Entity Framework profiler - ASP.NET MVC4 with EF 6 -Unable to determine the provider name

From Dev

How to retrieve image from database without using Entity Framework in ASP.NET MVC4

From Dev

ASP.NET MVC4 Entity Framework db.SaveChanges() Condition not working

From Dev

Concurrency in ASP .NET MVC 5 with Entity Framework

From Dev

403 Forbidden with Log4Net and MVC5

From Dev

Single or multiple DbContext File in mvc4 using Entity framework 6

From Dev

Assigning [Key] attribute to Entity Framework generated class - MVC4 C#

From Dev

MVC4 Code First Entity Framework Upload large files to a SQL Server database

From Dev

upload image in server folder and save path in Sqlserver using entity framework mvc4

From Dev

Merging MVC4 membership database with entity framework code first database

From Dev

Unable to Use an HtmlHelper in Razor syntax in MVC4 Intranet App using Entity Framework

From Dev

Assigning [Key] attribute to Entity Framework generated class - MVC4 C#

From Dev

upload image in server folder and save path in Sqlserver using entity framework mvc4

From Dev

How to perform edit function in MVC4 without using entity framework?

From Dev

What '%5rms' means in Log4Net ConfigurationFile?

Related Related

  1. 1

    PieChart in mvc4 from Entity Framework

  2. 2

    Dropdownlist and MVC4 Entity Framework

  3. 3

    List of users that not yet in any role, (MVC4 with SimpleMembership and entity framework 5)

  4. 4

    How can i create a Partial View for MVC4 or MVC 5 using Entity Framework (.edmx Model) with Razor Views?

  5. 5

    How to mock method with ViewModel in MVC4 with Entity Framework 4.0

  6. 6

    Will Orchard CMS support MVC4 with Entity Framework

  7. 7

    MVC4 Entity Framework Controller Database Issue

  8. 8

    MVC4 app - how to remove Entity Framework and implement SimpleMembershipProvider?

  9. 9

    How to mock method with ViewModel in MVC4 with Entity Framework 4.0

  10. 10

    MVC4 Entity Framework 6 Model State Validation Issues

  11. 11

    .NET Membership in ASP.NET MVC4 and Entity Framework with Oracle as Db

  12. 12

    Update entity in mvc4

  13. 13

    Entity Framework profiler - ASP.NET MVC4 with EF 6 -Unable to determine the provider name

  14. 14

    How to retrieve image from database without using Entity Framework in ASP.NET MVC4

  15. 15

    Entity Framework profiler - ASP.NET MVC4 with EF 6 -Unable to determine the provider name

  16. 16

    How to retrieve image from database without using Entity Framework in ASP.NET MVC4

  17. 17

    ASP.NET MVC4 Entity Framework db.SaveChanges() Condition not working

  18. 18

    Concurrency in ASP .NET MVC 5 with Entity Framework

  19. 19

    403 Forbidden with Log4Net and MVC5

  20. 20

    Single or multiple DbContext File in mvc4 using Entity framework 6

  21. 21

    Assigning [Key] attribute to Entity Framework generated class - MVC4 C#

  22. 22

    MVC4 Code First Entity Framework Upload large files to a SQL Server database

  23. 23

    upload image in server folder and save path in Sqlserver using entity framework mvc4

  24. 24

    Merging MVC4 membership database with entity framework code first database

  25. 25

    Unable to Use an HtmlHelper in Razor syntax in MVC4 Intranet App using Entity Framework

  26. 26

    Assigning [Key] attribute to Entity Framework generated class - MVC4 C#

  27. 27

    upload image in server folder and save path in Sqlserver using entity framework mvc4

  28. 28

    How to perform edit function in MVC4 without using entity framework?

  29. 29

    What '%5rms' means in Log4Net ConfigurationFile?

HotTag

Archive