Last post May 06, 2021 11:08 AM by comicrage
May 05, 2021 04:38 PM|comicrage|LINK
I am trying to add log to file functionality in my webapi 3.1 with Microsoft.Extensions.Logging.Log4Net.AspNetCore.
I am able to log to eventviewer and see the log information but I see no file created.
I followed the steps in the follings:
https://github.com/huorswords/Microsoft.Extensions.Logging.Log4Net.AspNetCore https://github.com/huorswords/Microsoft.Extensions.Logging.Log4Net.AspNetCore/blob/develop/doc/CONFIG.md Simplest
correct way to configure log4net for a .Net Core 3.1 application
According to GitHub, all I have to do is install the package, AddLog4Net in the startup.cs.
I am not sure why no logfile is generated.
But I had no success yet
Any help is greatly appreciated. Thanks
UPDATE: I went the github url:
and downloaded the sample code. When I removed the <configuration> tag, it worked.
May 06, 2021 07:21 AM|XuDong Peng|LINK
According to the code you provided, I have some confusion.
Did you modify part of the code? There are many problems with the code you have given, such as:
1. UserStartup<Startup>() UseStartup<Startup>()2. public static void SetupConfiguration(WebHostBuilderContext ctx, IConfiguration builder)IConfigurationBuilder interface.3. AddEnvironmentalVariables() AddEnvironmentVariables()4. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory) public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) 5. <staticLogFileName value="false"> <staticLogFileName value="false"/>
I'm not sure if this is all the existing problems, I modified them and ran the code. And found that the log file has been generated, it is located in the bin\Debug folder under the project path. Just like this:
If there is no exception during the code execution, you can check under the Bin file. I think this is because of the path configuration.
Hope this can help you.
May 06, 2021 11:08 AM|comicrage|LINK
Thanks for the help