Log4net logfile is not created in release mode for winforms application

I added the config in Assembly.cs

[assembly: log4net.Config.XmlConfigurator(Watch = true)]

here is my configuration

   <configSections>
   <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections> 
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="GetWorkLog.txt" />
  <!--C:/logs/my_log_file.log-->
  <appendToFile value="true" />
  <rollingStyle value="Date" />
  <maxSizeRollBackups value="10" />
  <maximumFileSize value="5MB" />
  <datePattern value=".yyyy-MM-dd" />
  <staticLogFileName value="true" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
  </layout>
</appender>

how to fix this issue?

In order to embed the configuration data in the .config file the section name must be identified to the .NET config file parser using a configSections element.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    </configSections>
    <log4net>
        <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
            </layout>
        </appender>
        <root>
            <level value="INFO" />
            <appender-ref ref="ConsoleAppender" />
        </root>
    </log4net>
</configuration>

Source: https://logging.apache.org/log4net/release/manual/configuration.html#dot-config

Log4net does not writes to log file, Check if your application has write permissions on destination folder for log file. [LOG4NET-257] - Visual Studio 2010 .NET 4.0 Application does not copy log4net lib to bin directory [LOG4NET-265] - RemoteFileAppender Tests fail on Windows 7 [LOG4NET-274] - log4net doesn't log when running a .Net 4.0 Windows application built in Release mode

I recommend to check through your .csproj file to see if it contains something like:

...
<ItemGroup Condition="Debug">
    ...    
    <None Include="App.config" />
    ...
</ItemGroup>
...

If so, replace this with:

...
<ItemGroup Condition="Debug">
    ...
</ItemGroup>
<ItemGroup>
    <None Include="App.config" />
</ItemGroup>
...

log4net dosen't log when running in release mod, Hi, I am using log4net to log different info in my windows project. It works fine when creating setup in "Debug" mode. But when created� Best How To : @peer is right, you need to pick one method of configuring log4net and use it correctly. I think your immediate problem though is you've specified app.config as the config file in your assembly attribute, but you must specify your_app_name.exe.config as that will be the file's name after the project is built (the name will differ depending on the actual name of your app, look in

I was having the same problem, the log4net worked fine before then it stopped all of a sudden. After a few hair pulling, I discovered that another app was using the log file. Without going into details of how my other application was using the same log file. Make sure that NO other application is using the log file, log4net is trying to write to.

Adding logging to a .NET application using log4net, 1 - Add the Nuget package to your project(s); 2 - Create the log4net Net v1, so if you are using another version of Visual Studio, that should not be a problem This configuration will show logs in both: the console and a rolling text it to debug mode as easy), but at least I can get my logs now centrally� </log4net> Logging works as expected when the service starts up while using the exe that was built in debug mode (log files are created at the right file path), but doesn't work when it is using the exe built in release mode. I've even tried using a recompiled log4net dll for .Net 4.0 following the steps mentioned at this blog..

log file is not created using log4net - MSDN, One of the project I have created has app.config where I have made The log file itself is not created and when I debug it runs through these codes properly. I am using log4net.dll version 1.2.13 for desktop applications using� I was having the same problem, the log4net worked fine before then it stopped all of a sudden. After a few hair pulling, I discovered that another app was using the log file. Without going into details of how my other application was using the same log file. Make sure that NO other application is using the log file, log4net is trying to write to.

Log4net Configuration: Logging Exactly the Way You Want It, You would use either log4j or log4net to log application events; this includes Universal Windows applications, and even WinForms applications. If you want to send your log4net logs to Scalyr, you can use a Scalyr Agent to Since reading logs is the thing that makes them valuable, why not take it to� log4net is still one of the most commonly used logging frameworks for .NET. While originally being a port of the log4j logging framework for Java, a lot has happened over the years, to make log4net a unique logging option for .NET/C# developers.

How to Do Logging in C# With Log4net, When writing code in C#, use log4net to implement logging. When an application or server crashes, a log simplifies troubleshooting The checksums are not as strong indicators as the PGP signature. to a remote host, to a text file with rolling logs, the Windows Event Log, or even to email via SMTP. Configure your application to use log4net. We'll create a simple application that also contains a library .dll, to see how easy it is to get logs from every parts of your application. So go ahead and create : a new console application called application. Add a new code library project to the solution and call it library.

Comments
  • What does your app.config look like? Are you registering log4net module anywhere?
  • @mariocatch updated the question, log file is generated in debug mode, it not working in release mode.
  • Add to the log4net node debug="true" for more information.
  • file is generated in debug mode, its not working in release mode
  • @GANI try calling XmlConfigurator.Configure(); from the startup of your app. Do that in lieu of the attribute configuration that you have now.
  • its working by adding this XmlConfigurator.Configure(), and creating logfile in bin folder. I added config to insert the loginfo to database, this is not working in release mode.How to fix this