Note that there are some explanatory texts on larger screens.

plurals
  1. POlog4net in Program.cs
    primarykey
    data
    text
    <p>I have just set up log4net in my C# WinForms application by adding the reference, adding the configuration to App.config and the load entry in AssemblyInfo.cs. The config is set to catch ALL levels.</p> <p>In my Program.cs, I am trying to make it catch every single error.</p> <p>I currently have this:</p> <pre><code> static class Program { /// &lt;summary&gt; /// The main entry point for the application. /// &lt;/summary&gt; private static readonly ILog log = LogManager.GetLogger(typeof(Program)); [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { log.Info("this works"); Application.Run(new Forms.Main()); } catch (Exception e) { log.Info("nothing here", e); } } } </code></pre> <p>I put the "this works" in just to test that I can actually write to the log file, and this what shows up in the log:</p> <pre><code>2012-09-30 23:00:53,959 [INFO ] - this works </code></pre> <p>My log4net is also set up to write to the Immediate Window, so I've created some errors on purpose and this is what I see in the window:</p> <pre><code>ContractManagement.Program: 2012-09-30 23:08:09,177 [INFO ] - this works A first chance exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll </code></pre> <p>I would have expected to see the second error in the logs as well, but there is no sign of it :(</p> <hr> <p>Following Keith Nicholas's comment, I have done this:</p> <pre><code>static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); log.Info("this works"); throw new System.ArgumentException("Keith Nicholas Test"); //Application.Run(new Forms.Main()); } </code></pre> <p>And the log file shows:</p> <pre><code>2012-09-30 23:19:12,090 [INFO ] - this works System.ArgumentException: Keith Nicholas Test at ContractManagement.Program.Main() in c:\ContractManagement\ContractManagement\Program.cs:line 25 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload