The. NET core framework itself is embedded in the log system. Instantiate Microsoft.Extensions.Logging.LoggerFactory start
Use the Iloggerfactory extension method to specify the provider you want to use. The code is as follows:
public static void Main (string[] args = null)
{
iloggerfactory loggerfactory = new Loggerfactory ()
. Addconsole ()
. Adddebug ();
ILogger logger = loggerfactory.createlogger<program> ();
Logger. Loginformation (
"This is a test of the emergency broadcast System.");
}
But out-of-the-box ILogger implementations (Microsoft.Extensions.Logging.Logger) do not have such exception handling, so if an exception occurs, you will need to invoke the code to handle it, and to do so, call LOGGER.LOGX each time. A common way to resolve this problem might be to wrap the logger to catch exceptions. Basically the output is on the console. And no output TXT file was found. You can't see anything on IIS when it's published.
So the decision is still to integrate log4net. First, add the Log4net package to the NuGet, adding the configuration file. Then add the following code to the startup file:
public static iloggerrepository repository {get; set;} public Startup (Ihostingenvironme NT Env) { var builder = new Configurationbuilder () & nbsp . Setbasepath (env. Contentrootpath) Addjsonfile ("Appsettings.json", Optional:false, Reloadonchange:true) &N BSP;. Addjsonfile ($ "appsettings.{ Env. Environmentname}.json ", Optional:true) .
Addenvironmentvariables (); Configuration = Builder.
Build (); //(Jacky 2017-06-27) Repository
= Logmanager.createrepository ("Netcorerepository"); Xmlconfigurator.configure (repository, New FileInfo ("Log4net.config")); }
Call log
var log = Logmanager.getlogger (repository. Name, typeof (Startup));
Log. Info ("test");