Skip to content
MVC Log4Net integration example File and database logs
JavaScript C# HTML Other
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.


# mvc_Log4Net
MVC Log4Net integration example File and database logs

This is a straightforward integration of Log4Net into a minimal ASP.NET MVC Web Application

Follow the following steps to make this work on your system

1. Run the .sql file in mvc_Log4Net\Models (Edit this for your needs as necessary but remember that you will have to change all references):
2. Import the database table as an Entity Framework Model from the database.
		you should get a web.config entry like the following:
    <!--//***Log4Net_Test EF6 connection string generated by importing database table LogEntries-->
    <add name="App_LogEntities" connectionString="metadata=res://*/Log4Net_Model.csdl|res://*/Log4Net_Model.ssdl|res://*/Log4Net_Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\sqlexpress;initial catalog=App_Log;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Then search for the pattern "//***Log4Net_Test" to find all the modifications made to a default VS2015 ASP.NET MVC .NET web application 

The above preparations and all other edits are returnd by searching for the pattern "//***Log4Net_Test" in all project .cs and .cshtml files:

  C:\Projects\__Public\POC\mvc_Log4Net\mvc_Log4Net\Controllers\HomeController.cs(13):            //***Log4Net_Test
  C:\Projects\__Public\POC\mvc_Log4Net\mvc_Log4Net\Controllers\Log4Net_TestController.cs(9)://***Log4Net_Test: include this entire file
  C:\Projects\__Public\POC\mvc_Log4Net\mvc_Log4Net\Global.asax.cs(20):            //***Log4Net_Test: Initializer, no output without this configuration, make sure your log4net.config file is in the web application root
  C:\Projects\__Public\POC\mvc_Log4Net\mvc_Log4Net\Log.cs(6)://***Log4Net_Test: include this entire file
  C:\Projects\__Public\POC\mvc_Log4Net\mvc_Log4Net\Views\Home\Index.cshtml(9):        @* //***Log4Net_Test default test entry link *@
  C:\Projects\__Public\POC\mvc_Log4Net\mvc_Log4Net\Views\Log4Net_Test\Index.cshtml(5):@* //***Log4Net_Test: shows how to generate test log entries and view them   *@
 Run the app and select 'Generate test log entries'.
You can’t perform that action at this time.