Log4Net doesn't log

Topics: Installing BugNET
Feb 7, 2013 at 6:56 PM
I am running the latest BugNet version (fresh install, not an upgrade) on IIS8 Windows Server 2012. When I try to enable the Pop3 mailbox integration there is no feedback in terms of logs or error messages. I have searched through every thread in the discussions and tried changing my log level to ALL and the only thing in my log is something about the mailbox.dll repository not being found.

How can I get better error messaging to resolve my problem?
Feb 8, 2013 at 2:54 PM
Most of the time when you get a "repository" not found in log4net it usually means log4net is not configured properly (from what I have found anyways).

If you have not done this already in the log4net.config file make sure that the connection string matches what is in your web.config. The value attribute should be the same as the connectionString attribute of the web.config.
<connectionString value="Data Source=.\SQL2008;Database=BugNET;Integrated Security=True;" />
You can also try this config (comment out the connectionString element)
<connectionStringName value="BugNET" />
Feb 12, 2013 at 5:22 PM
I deleted my BugNet install, grabbed the latest (1.3 from source) and reinstalled. The logging didn’t work. I then checked my connection string in log4net.config and tried both methods that you listed. I am still not getting any logging. My log4net internal log shows the following:
log4net: log4net assembly [log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821]. Loaded from [C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\2dd062f6\52ef7bf9\assembly\dl3\c6559e30\006f7b3a_8a08ce01\log4net.dll]. (.NET Runtime [4.0.30319.18010] on Microsoft Windows NT 6.2.9200.0)
log4net: DefaultRepositorySelector: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository for assembly [BugNET.HttpModules.MailBoxReader, Version=1.3.242.0, Culture=neutral, PublicKeyToken=null]
log4net: DefaultRepositorySelector: Assembly [BugNET.HttpModules.MailBoxReader, Version=1.3.242.0, Culture=neutral, PublicKeyToken=null] Loaded From [C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\2dd062f6\52ef7bf9\assembly\dl3\e0d23b1a\813aebee_9d08ce01\BugNET.HttpModules.MailBoxReader.dll]
log4net: DefaultRepositorySelector: Assembly [BugNET.HttpModules.MailBoxReader, Version=1.3.242.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified.
log4net: DefaultRepositorySelector: Assembly [BugNET.HttpModules.MailBoxReader, Version=1.3.242.0, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository [log4net-default-repository] using type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository for assembly [BugNET, Version=1.3.242.0, Culture=neutral, PublicKeyToken=null]
log4net: DefaultRepositorySelector: Assembly [BugNET, Version=1.3.242.0, Culture=neutral, PublicKeyToken=null] Loaded From [C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\2dd062f6\52ef7bf9\assembly\dl3\6a0b0eb8\00c21f98_4309ce01\BugNET.dll]
log4net: DefaultRepositorySelector: Assembly [BugNET, Version=1.3.242.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified.
log4net: DefaultRepositorySelector: Assembly [BugNET, Version=1.3.242.0, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: repository [log4net-default-repository] already exists, using repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: Creating repository for assembly [BugNET.BLL, Version=1.3.242.0, Culture=neutral, PublicKeyToken=null]
log4net: DefaultRepositorySelector: Assembly [BugNET.BLL, Version=1.3.242.0, Culture=neutral, PublicKeyToken=null] Loaded From [C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\2dd062f6\52ef7bf9\assembly\dl3\42c8c65e\002a3aee_9d08ce01\BugNET.BLL.dll]
log4net: DefaultRepositorySelector: Assembly [BugNET.BLL, Version=1.3.242.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified.
log4net: DefaultRepositorySelector: Assembly [BugNET.BLL, Version=1.3.242.0, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: DefaultRepositorySelector: repository [log4net-default-repository] already exists, using repository type [log4net.Repository.Hierarchy.Hierarchy]
Any ideas? I really need to get logging to work in order to figure out why I can’t get the Subversion hooks and pop3 email integration working.
Feb 12, 2013 at 5:27 PM
Edited Feb 12, 2013 at 5:29 PM
And there is nothing in the database BugNet_ApplicationLog table?
Feb 12, 2013 at 5:31 PM
I see nothing under "Admin-->Log Viewer" and there are no rows in the "BugNet_ApplicationLog" table in my database. Also, I can successfully create new projects and issues, so I have a working database connection.
Feb 12, 2013 at 5:33 PM
Is your connection string named "BugNET"?
Feb 12, 2013 at 5:51 PM
Yes (and thanks for your quick responses!).

Here's my log4net config (I named my database "Support" instead of "BugNet"):
<?xml version="1.0" encoding="utf-8"?>
<log4net>
    <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
        <bufferSize value="1" />
        <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <connectionString value="Data Source=REACHAPP01;Initial Catalog=Support;Integrated Security=True" />
        <commandText value="INSERT INTO BugNet_ApplicationLog ([Date],[Thread],[Level],[Logger],[User],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @user, @message, @exception)" />
        <parameter>
            <parameterName value="@log_date" />
            <dbType value="DateTime" />
            <layout type="log4net.Layout.RawTimeStampLayout" />
        </parameter>
        <parameter>
            <parameterName value="@thread" />
            <dbType value="String" />
            <size value="255" />
            <layout type="log4net.Layout.PatternLayout" value="%thread" />
        </parameter>
        <parameter>
            <parameterName value="@log_level" />
            <dbType value="String" />
            <size value="50" />
            <layout type="log4net.Layout.PatternLayout" value="%level" />
        </parameter>
        <parameter>
            <parameterName value="@logger" />
            <dbType value="String" />
            <size value="255" />
            <layout type="log4net.Layout.PatternLayout" value="%logger" />
        </parameter>
        <parameter>
            <parameterName value="@user" />
            <dbType value="String" />
            <size value="50" />
            <layout type="log4net.Layout.PatternLayout" value="%X{user}" />
        </parameter>
        <parameter>
            <parameterName value="@message" />
            <dbType value="String" />
            <size value="4000" />
            <layout type="log4net.Layout.PatternLayout" value="%message" />
        </parameter>
        <parameter>
            <parameterName value="@exception" />
            <dbType value="String" />
            <size value="2000" />
            <layout type="log4net.Layout.ExceptionLayout" />
        </parameter>
    </appender>
    <root>
        <level value="ALL" />
        <appender-ref ref="AdoNetAppender" />
    </root>
</log4net>
and here's my web.config:
  <connectionStrings>
    <clear />
    <add name="BugNET" connectionString="Data Source=REACHAPP01;Initial Catalog=Support;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <clear />
    <add key="InstallationDate" value="4/28/2007" />
    <add key="log4net.Internal.Debug" value="true" />
  </appSettings>
Feb 12, 2013 at 5:54 PM
FYI, My method for trying to get a new log added to the table is to input a false SMTP email server name and then click "test." If this doesn't generate an error in the logs then I need another way of testing.
Feb 12, 2013 at 7:35 PM
Edited Feb 12, 2013 at 7:36 PM
Update:

I am running off of the source code, so I just attempted to get BugNET running in my development environment (VS2012). I copied the database from my live server to my dev server and then ran on my local dev box and the logging worked!

I changed my log4net.config connection string to work in both environments:
<connectionStringName value="BugNET" />
The difference between the dev version and the live version is the connection string in the web.config (dev = SQL2012Express on dev server, live = SQL2012 on live server). The live site is running in IIS8 whereas the dev site is running on my local dev box's IISExpress launched by VS2012 (in Win 7).

Any ideas of why it won't work on my live server? Problems with IIS8 or SQLServer2012?
Feb 13, 2013 at 2:36 PM
I'm having the exact same problem on af Win 2012 and SQL 2012 - no logging at all.
Not even if i configure a simple file appender in log4net.config
Feb 13, 2013 at 2:46 PM
Are you guys running under medium trust?
Feb 13, 2013 at 2:50 PM
Edited Feb 13, 2013 at 2:54 PM
Under medium trust?

The fileappender actually creates the file and writes a "INFO BugNET.Initialization [(null)] - Application Start" but that is the only thing being logged.
Even with loglevel Debug.

The internal log4net log don't show any errors.

Edit: Running full trust
Feb 13, 2013 at 2:51 PM
I'm running at Trust Level = Full (Internal) in my IIS settings for the site. The web.config came with a Trust Level = Medium that is commented out.
Feb 13, 2013 at 2:54 PM
Edited Feb 13, 2013 at 2:55 PM
Thornton wrote:
Under medium trust?

The fileappender actually creates the file and writes a "INFO BugNET.Initialization [(null)] - Application Start" but that is the only thing being logged.
Even with loglevel Debug.

The internal log4net log don't show any errors.
This looks as if the logging is working correctly, but I am unsure why it would not log to the sql server database. The connection string must be named "BugNET" in the web.config, on first initialization of the web app, the log4net config is updated on the fly with this connection string.
Feb 13, 2013 at 3:00 PM
I don't know what the h... just happende, but now i actually logs errors to both the SQL and the fileappender.

Is is correct that there is no debug logging done anywhere?
Feb 13, 2013 at 3:40 PM
Thornton wrote:
I don't know what the h... just happende, but now i actually logs errors to both the SQL and the fileappender.

Is is correct that there is no debug logging done anywhere?
Magic? There is debug logging but most of it is in the mailbox reader / authentication modules.
Feb 13, 2013 at 5:32 PM
Apparently :-)

Only in the mailbox reader/auth modules? Because i still haven't seen a single debug log entry
Feb 13, 2013 at 5:35 PM
Thornton wrote:
Apparently :-)

Only in the mailbox reader/auth modules? Because i still haven't seen a single debug log entry
There are info / warning log entries, no debug.

http://bugnet.codeplex.com/SourceControl/changeset/view/14c96ad30e32#src/BugNET.MailboxReader/MailboxReader.cs
Feb 13, 2013 at 5:40 PM
OK. Still wierd. I just sent mails thru the box (and they are correctly created as issues) but no info was logged.

There is also no error logged when doing a SMTP test against a invalid servername

This is my log4net.config

<?xml version="1.0" encoding="utf-8"?>
<log4net>
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
    <bufferSize value="1" />
    <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <connectionString value="Data Source=sql.thornton.local\prod;Database=BugNETTimeView2;User ID=....;Password=...;" />
    <commandText value="INSERT INTO BugNet_ApplicationLog ([Date],[Thread],[Level],[Logger],[User],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @user, @message, @exception)" />
    <parameter>
        <parameterName value="@log_date" />
        <dbType value="DateTime" />
        <layout type="log4net.Layout.RawTimeStampLayout" />
    </parameter>
    <parameter>
        <parameterName value="@thread" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout" value="%thread" />
    </parameter>
    <parameter>
        <parameterName value="@log_level" />
        <dbType value="String" />
        <size value="50" />
        <layout type="log4net.Layout.PatternLayout" value="%level" />
    </parameter>
    <parameter>
        <parameterName value="@logger" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout" value="%logger" />
    </parameter>
    <parameter>
        <parameterName value="@user" />
        <dbType value="String" />
        <size value="50" />
        <layout type="log4net.Layout.PatternLayout" value="%X{user}" />
    </parameter>
    <parameter>
        <parameterName value="@message" />
        <dbType value="String" />
        <size value="4000" />
        <layout type="log4net.Layout.PatternLayout" value="%message" />
    </parameter>
    <parameter>
        <parameterName value="@exception" />
        <dbType value="String" />
        <size value="2000" />
        <layout type="log4net.Layout.ExceptionLayout" />
    </parameter>
</appender>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="d:\tmp\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="Debug" />
    <appender-ref ref="AdoNetAppender" />
    <appender-ref ref="FileAppender" />
</root>
</log4net>
Feb 19, 2013 at 8:34 PM
I fixed the problem, at least for my case. Please take note of this because you may want to update the code base.

In global.asax.cs:
    protected void Application_Start(object sender, EventArgs e)
    {
        Log.Info("Application Start");
    }
This solved the problem because it initializes the Logger as early as possible (instead of later in Application_BeginRequest()).

Here's a link to the faq. Check out the section on not logging in release mode (which appeared to be my problem, but only on my server and not in my dev environment).
Apr 11, 2013 at 1:38 PM
Had the same problem on a fresh / clean install and nothing was being logged for the Mail Reader. You don't even get the normal "Application Start" message from further down the code being logged. However, merrittn's change to global.asax.cs works and now log4net is updating the database correctly.

I still have issues with the FileAppender not working despite IUSR have full permissions to the folder and file. But at least I now got something to work on.
Oct 16, 2013 at 8:52 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.