Question : using log4net in debug mode only writes to db when stopping debug.

How can I fix so when in debug mode log4net writes to the db immediatel?

 <log4net>
    <appender name="AdoNetAppender_SqlServer" type="log4net.Appender.AdoNetAppender">
      <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      <connectionString value="Data Source=WM7-1111-MATHC;Initial Catalog= ;Integrated Security=True;" providerName="System.Data.SqlClient"/>
      <commandText value="INSERT INTO OWU_Log4Net ([Date],[Level],[Logger],[User],[Message],[Exception],[Thread]) VALUES (@log_date, @log_level, @logger, @user, @message, @exception, @thread)"/>
      <parameter>
        <parameterName value="@log_date"/>
        <dbType value="DateTime"/>
        <layout type="log4net.Layout.RawTimeStampLayout"/>
      </parameter>
      <parameter>
        <parameterName value="@log_level"/>
        <dbType value="String"/>
        <size value="50"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%p"/>
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@logger"/>
        <dbType value="String"/>
        <size value="255"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%c"/>
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@user"/>
        <dbType value="String"/>
        <size value="50"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%X{user}"/>
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@message"/>
        <dbType value="String"/>
        <size value="4000"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%m"/>
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@exception"/>
        <dbType value="String"/>
        <size value="2000"/>
        <layout type="log4net.Layout.ExceptionLayout"/>
      </parameter>
      <parameter>
        <parameterName value="@thread"/>
        <dbType value="String"/>
        <size value="255"/>
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%t"/>
        </layout>
      </parameter>
    </appender>
    <root>
      <level value="ALL"/>
      <appender-ref ref="AdoNetAppender_SqlServer"/>
    </root>
  </log4net>
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
using System;
using System.Collections.Generic;
using System.Text;

using log4net;

public static class Log
{
   private const string LOG_REPOSITORY = "Default"; // this should likely be set in the web config.
   private static ILog m_log;

   public static void Init()
   {
      log4net.Config.XmlConfigurator.Configure();
   }

   public static void Write(string message, LogMessageType messageType)
   {
      DoLog(message, messageType, null, Type.GetType("System.Object"));
   }

   public static void Write(string message, LogMessageType messageType, Type type)
   {
      DoLog(message, messageType, null, type);
   }

   public static void Write(string message, LogMessageType messageType, Exception ex)
   {
      DoLog(message, messageType, ex, Type.GetType("System.Object"));
   }

   public static void Write(string message, LogMessageType messageType, Exception ex,
      Type type)
   {
      DoLog(message, messageType, ex, type);
   }

   public static void Assert(bool condition, string message)
   {
      Assert(condition, message, Type.GetType("System.Object"));
   }

   public static void Assert(bool condition, string message, Type type)
   {
      if (condition == false)
         Write(message, LogMessageType.Info);
   }

   private static void DoLog(string message, LogMessageType messageType, Exception ex,
      Type type)
   {
      m_log = LogManager.GetLogger(type);

      switch (messageType)
      {
         case LogMessageType.Debug:
            Log.m_log.Debug(message, ex);
            break;

         case LogMessageType.Info:
            Log.m_log.Info(message, ex);
            break;

         case LogMessageType.Warn:
            Log.m_log.Warn(message, ex);
            break;

         case LogMessageType.Error:
            Log.m_log.Error(message, ex);
            break;

         case LogMessageType.Fatal:
            Log.m_log.Fatal(message, ex);
            break;
      }
   }

   public enum LogMessageType
   {
      Debug,
      Info,
      Warn,
      Error,
      Fatal
   }
}

Answer : using log4net in debug mode only writes to db when stopping debug.

For iterators... It may look not so at the first time, but iterators are a kind of more natural.  When you solve a problem, you tend to think in terms "process all elements from...", or mathematically "for all elements in...".  The only conventional way to do that is to use a loop.  The while loop in C-family languages is too general; you have do some steps on your own.  The for loop in C-family languages is a small syntactic improvement of the while.  In other programming languages, the for loop is a counted loop.  But this also means that you have to transform an index to the indexed element.  Because of that, you often tend to put the elements into some indexed structure -- to an array or to a vector.

If you think more about it, what your really need is a kind of generalized loop that loops through all elements of a container without neccessarily preparing some numeric index.  If you personify the process, the worker says to another one "give me the next one", and not "give me the 3254th one".  This is exactly what iterators are good for.  The iterator is somehow type-bound to the container.  Then you may be not interested in internal details (whether it is indexed inside, or whether it is a linked structure).  In other words, the iterators bring more abstraction.

Unfortunately, the iterators are newer than the core of C++ and therefore there is no generalized loop and syntax to make all of this more apparent syntactically.  Once you get used to better sytax of the generalized loop (in other languages, like in Python where iterators work almost magically, hidden), you really miss that syntax in C++.  The new C++ standard is going to improve it a bit.
Random Solutions  
 
programming4us programming4us