Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

Log4Net creating empty Log file

$
0
0

Hi I am trying to write my console output to a log file and i only see it created a log file but it is not writing anything into the log file.

Please find the below attached App.config and AssemblyInfo.cs filesand also the changes i have done to my code.

app.config

<?xml version="1.0" encoding="utf-8" ?><configuration><configSections><section name="log4net"             type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/></configSections><log4net><root><level value="INFO"/><level value="DEBUG"/><level value="ERROR"/><appender-ref ref="FileAppender" /></root><appender name="FileAppender" type="log4net.Appender.FileAppender"><file value="D:\Logs\abc.log" /><appendToFile value="true" /><lockingModel type="log4net.Appender.FileAppender+MinimalLock" /><layout type="log4net.Layout.PatternLayout"><conversionPattern value="%date [%thread] %level %logger - %message%newline" /></layout><filter type="log4net.Filter.LevelRangeFilter"><levelMin value="INFO" /><levelMax value="ERROR" /></filter></appender></log4net></configuration>

Assemblyinfo.cs

using System.Reflection;using System.Runtime.CompilerServices;using System.Runtime.InteropServices;//Log4Net Configurations[assembly: log4net.Config.XmlConfigurator(Watch = true)][assembly: ComVisible(false)]

C# Console App Code:

 class Program    {        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);        public static void Main(string[] args)        {               try            {                if (Directory.Exists(LogPath))                 {                    log.Info("Log Directory Exists, Starting execution");                    Console.WriteLine(LogPath, "Directory Exists {0}");                    log.Debug("Checking for Log Directory, It Exists !!");                }                else                {                    Console.WriteLine(LogPath, "Doesn't Exists, Creating the Folder");                    DirectoryInfo LogPathfolder = Directory.CreateDirectory(LogPath);                    log.Info("Creating LogPath Folder");                }            }            catch (Exception e)            {                Console.WriteLine(e.Message);                log.Error(e.Message);            }        }}

Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>