views:

246

answers:

1

I am trying to use log4net in a VB.NET app for some unknown reason it's not creating the log file.

Here is my app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
       <configSections>
    <section name="log4net"
    type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
  <log4net>
    <appender name="FileAppender" type="log4net.Appender.FileAppender">
      <file value="c:\log-file.txt" />
      <appendToFile value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
    </appender>
    <root>
      <level value="ALL" />
      <appender-ref ref="FileAppender" />
    </root>

  </log4net>
</configuration>

Here is the app code

Imports log4net
Public Class Form1
    Dim log As ILog
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        log.Error("test")
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        log4net.Config.XmlConfigurator.Configure()
        log = log4net.LogManager.GetLogger("TestThings")
    End Sub
End Class

"TestThings" is the name of the VS project. What am I missing?

Edit ~ I am logged in as admin and I am using the most recent log4net.dll

+1  A: 

try this:

change

< appender name="FileAppender" type="log4net.Appender.FileAppender" >

to

< appender name="FileAppender" type="log4net.Appender.FileAppender, log4net" >

add log4net also to

< layout type="log4net.Layout.PatternLayout" >
sza