Ron Grabowski | 1 Feb 2012 03:09
Picon
Favicon

Re: Can log4net return exceptions back

Implement your own IErrorHandler:

http://logging.apache.org/log4net/release/sdk/log4net.Appender.AdoNetAppenderMembers.html
http://logging.apache.org/log4net/release/sdk/log4net.Core.IErrorHandler.html

From: Roman Konovalov <roman <at> greenrain.biz>
To: log4net-user <at> logging.apache.org
Sent: Sunday, January 29, 2012 6:24 AM
Subject: Can log4net return exceptions back

Hi,
 
Is it possible to setup log4net to re-throw exceptions back to caller? For example, if logging to database is timed out, we might want to save such exception to a file or to send e-mail to the support team. Thank you.
 
Best regards,
Roman
 


Ron Grabowski | 1 Feb 2012 03:13
Picon
Favicon

Re: Performance saving logs to the database

If you're on SQL Server, try this:

https://github.com/lorenzomelato/rhino-commons/blob/master/Rhino.Commons/Logging/AsyncBulkInsertAppender.cs

From: Roman Konovalov <roman <at> greenrain.biz>
To: log4net-user <at> logging.apache.org
Sent: Sunday, January 29, 2012 6:25 AM
Subject: Performance saving logs to the database

Hi,
 
We have web server with about 60,000 page visits a day. Within the next 6 months the load is expected to reach 1,000,000 page visits a day. We use log4net to store logs into the log database.
What is now unclear to me is if log4net is able to manage such a big load from performance point of view. Log4net is synchronous and if log database is down, then the entire process is waiting for log4net return call back (I assume it returns call back when database connection timeout occurs).
 
Should we write our own appender to save logs into the database asynchronously?
Or we would revisit our logging strategy and log only exceptions and errors in production environment, turning on other levels of logging during troubleshooting time?
 
Many thanks for replies.
 
Best regards,
Roman
 


mmingfeilam | 1 Feb 2012 20:12
Picon

log4net AdoNetAppender common connectionstring value


i have two exes in my solution that are run simultaeneously.  each exe has a
log4net.xml file with a AdoNetAppender in it:
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
    <bufferSize value="100" />
    <connectionType value="System.Data.SqlClient.SqlConnection, System.Data,
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <connectionString value="data source=[database server];initial
catalog=[database name];integrated security=false;persist security
info=True;User ID=[user];Password=[password]" />
    <commandText value="INSERT INTO Log
([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES ( <at> log_date,
 <at> thread,  <at> log_level,  <at> logger,  <at> message,  <at> exception)" />
    <parameter>

is there any way to move the value of the connectionstring to a common file
and just reference it by name?  would it be possible to move the appenders
to one common location as well?  i want to do it using a config file and not
programmatically.  thanks.

--

-- 
View this message in context: http://old.nabble.com/log4net-AdoNetAppender-common-connectionstring-value-tp33244792p33244792.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Todd | 1 Feb 2012 20:40
Picon
Favicon

Re: log4net AdoNetAppender common connectionstring value

I do something along that line. I have a connection string inside machine.config and I wrapped l4n in a wrapper dll that's used in many projects. I actually deploy a logging config file alongside the wrapper, so some of the code here is accessing settings inside that. The logging CN is in machine.config because it's used elsewhere, as well.
 
So the wraper calls ConfigureLogging() from wrapper logging methods that I expose. My apps don't actually deal with l4n directly. Each one simply checks if initialization is needed before forwarding into l4n.
 
In the wrapper class I do this:
 
        private static void ConfigureLogging()
        {
            string assemblyPath = string.Empty;
            Configuration cfg = null;
            try
            {
                string connectionString = string.Empty;
                assemblyPath = Assembly.GetExecutingAssembly().Location;
                try
                {
                    cfg = ConfigurationManager.OpenExeConfiguration(assemblyPath);
                }
                catch (Exception ex)
                {
                    string msg = string.Format("Failed to load configuration file");
                    throw new ApplicationException(msg, ex);
                }
                if (!cfg.HasFile)
                {
                    string msg = string.Format("Failed to load configuration file");
                    throw new ApplicationException(msg);
                }
                // Connection strings come from machine.config, even though we're explicitly going after the app.dll.config
                if((cfg.ConnectionStrings == null) || cfg.ConnectionStrings.ConnectionStrings == null || cfg.ConnectionStrings.ConnectionStrings.Count == 0)
                    throw new ApplicationException("Framework could not to locate connection string collection in machine.config");

                ConnectionStringSettings cstr = cfg.ConnectionStrings.ConnectionStrings["CentralLogging"];
                if (cstr == null)
                    throw new ApplicationException("Framework could not locate 'CentralLogging' connection string.");
                connectionString = cfg.ConnectionStrings.ConnectionStrings["CentralLogging"].ConnectionString;
                connectionString += string.Format(";Application Name={0}; ", DatabaseApplicationName);
                try
                {
                    // Now we're using the local app.dll.config file
                    FileInfo fi = new FileInfo(cfg.FilePath);
                    if (fi.Exists)
                    {
                        // array of LogLog objects. Silly, eh?
                        ArrayList configurationMessages = (ArrayList)log4net.Config.XmlConfigurator.Configure(fi);
                        if (configurationMessages.Count > 0)
                        {
                            foreach (log4net.Util.LogLog l in configurationMessages)
                            {
                                if (l.Exception != null)
                                    _configurationMessages.Add(l.Exception);
                                else
                                    _configurationMessages.Add(l.Message);
                            }
                        }
                    }
                    else
                    {
                        string msg = string.Format("Missing configuration file'{0}'", assemblyPath);
                        throw new ApplicationException(msg);
                    }
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Framework unable to configure log4net by pointing it to the cfg file.", ex);
                }
                try
                {
                    ConnectLog4NetAppenders(connectionString);
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Framework unable to connect log4net appenders.", ex);
                }
            }
            catch (Exception ex)
            {
                Exception innerEx = ex;
                while(innerEx.InnerException != null)
                    innerEx = innerEx.InnerException;
                string cfgFilePath = "Unknown";
                if (cfg != null)
                    cfgFilePath = cfg.FilePath;
 
                string msg = string.Format("{0}.\nAssembly Location: {1}\ncfg.FilePath: {2}\n", ex.Message, assemblyPath, cfgFilePath);
                throw new ApplicationException(msg, innerEx);
            }
        }
        private static void ConnectLog4NetAppenders(string connectionString)
        {
            log4net.Repository.Hierarchy.Hierarchy hier = log4net.LogManager.GetRepository() as log4net.Repository.Hierarchy.Hierarchy;
            if (hier != null)
            {
                //string cnStr = "data source=do-sqld1;initial catalog=Admin;integrated security=true;persist security info=True";
                foreach (log4net.Appender.IAppender appender in hier.GetAppenders())
                {
                    if (appender.GetType() == typeof(log4net.Appender.AdoNetAppender) && !string.IsNullOrEmpty(connectionString))
                    {
                        log4net.Appender.AdoNetAppender sqlAppender = (log4net.Appender.AdoNetAppender)appender;
                        sqlAppender.ConnectionString = connectionString;
                        // In order to get these custom id values into the log, we have to dynamically create parameters and populate them.
                        // This is because log4net does not expose the command object, or existing parameter objects. If we defined them
                        // in the config file, we'd be updating their properties here, but instead, we have to create them entirely here.
                        // Note that the command text is still defined in the config file and references these parameters, even though they
                        // won't exist up until this point.
                        sqlAppender.AddParameter(CreateSystemIdParameter(" <at> system_name", SystemName));
                        sqlAppender.AddParameter(CreateSystemIdParameter(" <at> system_tag", SystemTag));
                       
                        sqlAppender.ActivateOptions(); //refresh settings of appender 
                    }
                }
            }
        }

 
From: mmingfeilam <lam.m <at> comcast.net>
To: log4net-user <at> logging.apache.org
Sent: Wednesday, February 1, 2012 2:12 PM
Subject: log4net AdoNetAppender common connectionstring value


i have two exes in my solution that are run simultaeneously.  each exe has a
log4net.xml file with a AdoNetAppender in it:
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
    <bufferSize value="100" />
    <connectionType value="System.Data.SqlClient.SqlConnection, System.Data,
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <connectionString value="data source=[database server];initial
catalog=[database name];integrated security=false;persist security
info=True;User ID=[user];Password=[password]" />
    <commandText value="INSERT INTO Log
([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES ( <at> log_date,
<at> thread, <at> log_level, <at> logger, <at> message, <at> exception)" />
    <parameter>

is there any way to move the value of the connectionstring to a common file
and just reference it by name?  would it be possible to move the appenders
to one common location as well?  i want to do it using a config file and not
programmatically.  thanks.


--
View this message in context: http://old.nabble.com/log4net-AdoNetAppender-common-connectionstring-value-tp33244792p33244792.html
Sent from the Log4net - Users mailing list archive at Nabble.com.



mmingfeilam | 2 Feb 2012 01:16
Picon

Re: log4net AdoNetAppender common connectionstring value


"
I do something along that line. I have a connection string inside
machine.config and I wrapped l4n in a wrapper dll that's used in many
projects. I actually deploy a logging config file alongside the wrapper, so
some of the code here is accessing settings inside that. The logging CN is
in machine.config because it's used elsewhere, as well.
 
So the wraper calls ConfigureLogging() from wrapper logging methods that I
expose. My apps don't actually deal with l4n directly. Each one simply
checks if initialization is needed before forwarding into l4n."
 
so you are doing this programmatically, is there a way to do it using the
configuration file, something along the line of:

<connectionString configSource="myConnectionStringFile" .../>
--

-- 
View this message in context: http://old.nabble.com/log4net-AdoNetAppender-common-connectionstring-value-tp33244792p33245873.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Ron Grabowski | 3 Feb 2012 05:16
Picon
Favicon

Re: log4net AdoNetAppender common connectionstring value

Maybe you could share a common App.Config between the two apps and use this to set the connection string:

http://logging.apache.org/log4net/release/sdk/log4net.Appender.AdoNetAppender.ConnectionStringName.html

From: mmingfeilam <lam.m <at> comcast.net>
To: log4net-user <at> logging.apache.org
Sent: Wednesday, February 1, 2012 7:16 PM
Subject: Re: log4net AdoNetAppender common connectionstring value



"
I do something along that line. I have a connection string inside
machine.config and I wrapped l4n in a wrapper dll that's used in many
projects. I actually deploy a logging config file alongside the wrapper, so
some of the code here is accessing settings inside that. The logging CN is
in machine.config because it's used elsewhere, as well.
 
So the wraper calls ConfigureLogging() from wrapper logging methods that I
expose. My apps don't actually deal with l4n directly. Each one simply
checks if initialization is needed before forwarding into l4n."
 
so you are doing this programmatically, is there a way to do it using the
configuration file, something along the line of:

<connectionString configSource="myConnectionStringFile" .../>
--
View this message in context: http://old.nabble.com/log4net-AdoNetAppender-common-connectionstring-value-tp33244792p33245873.html
Sent from the Log4net - Users mailing list archive at Nabble.com.



Byron Neudesic | 8 Feb 2012 18:42

UpdAdapter does not seem to be working


Hi All,
I have been attempting to use the UdpAdapter and Chainsaw to demonstrate
alternative logging methods. It does not seem that when I try to send a log
message that the UdpAdapter is actually sending messages.

 I am sending messages to the event logger, and that is just fine. I am
wondering if there are some advice I can be given to determine the possible
cause of my issues.

I am running Windows 7 Enterprise 64 bit, VS 2010 Ultimate using the NET 4.0
framework.

To troubleshoot, I also installed Wireshark to have an independent tool to
determine if messages are getting sent. It registers no messages on the port
that I have selected to send the logging. I have disabled my firewall to see
if that would resolve the problem.

I am not getting any errors from the logger to indicate that I am not able
to initalize the appender. However, when I look at the appender collection
on the log instance, it shows a count of zero. This is the case even when I
successfully log to the the event log, so I am not sure if that is a
concern.

I know that UDP is not guaranteed delivery; I am OK with that. I just want
to know that I am actually sending the messages.

Here is my config for my app:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
  </configSections>
  <appSettings>
  </appSettings>
  <log4net>
    <appender name="UdpAppender" type="log4net.Appender.UdpAppender">
      <remoteAddress value="127.0.0.1" />
      <remotePort value="13925" />
      <layout type="log4net.Layout.PatternLayout, log4net">
        <conversionPattern value="%-5level %logger [%property{NDC}] -
%message%newline" />
      </layout>
    </appender>
    <appender name="EventLogAppender"
type="log4net.Appender.EventLogAppender" >
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger
[%property{NDC}] - %message%newline" />
      </layout>
    </appender>
    <root>
      <level value="ALL" />
      <appender-ref ref="UdpAppender" />
      <appender-ref ref="EventLogAppender" />
    </root>
  </log4net>
</configuration>

Here is the config for Chainsaw:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration >
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="true">
   <plugin name="UDPReceiver" class="org.apache.log4j.net.UDPReceiver">

   </plugin>
   <root>
      <level value="debug"/>
   </root>
</log4j:configuration>

Thanks in advance,
Byron

--

-- 
View this message in context: http://old.nabble.com/UpdAdapter-does-not-seem-to-be-working-tp33287879p33287879.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Scott Deboy | 8 Feb 2012 19:02
Picon

Re: UpdAdapter does not seem to be working

It looks like this is an ipv6 issue with windows 7? 

Looks like you can use 127.0.0.2 instead of 127.0.0.1 to get around the issue.

On Wed, Feb 8, 2012 at 9:42 AM, Byron Neudesic <byron.goodman <at> neudesic.com> wrote:

Hi All,
I have been attempting to use the UdpAdapter and Chainsaw to demonstrate
alternative logging methods. It does not seem that when I try to send a log
message that the UdpAdapter is actually sending messages.

 I am sending messages to the event logger, and that is just fine. I am
wondering if there are some advice I can be given to determine the possible
cause of my issues.

I am running Windows 7 Enterprise 64 bit, VS 2010 Ultimate using the NET 4.0
framework.

To troubleshoot, I also installed Wireshark to have an independent tool to
determine if messages are getting sent. It registers no messages on the port
that I have selected to send the logging. I have disabled my firewall to see
if that would resolve the problem.

I am not getting any errors from the logger to indicate that I am not able
to initalize the appender. However, when I look at the appender collection
on the log instance, it shows a count of zero. This is the case even when I
successfully log to the the event log, so I am not sure if that is a
concern.

I know that UDP is not guaranteed delivery; I am OK with that. I just want
to know that I am actually sending the messages.

Here is my config for my app:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <configSections>
   <section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
 </configSections>
 <appSettings>
 </appSettings>
 <log4net>
   <appender name="UdpAppender" type="log4net.Appender.UdpAppender">
     <remoteAddress value="127.0.0.1" />
     <remotePort value="13925" />
     <layout type="log4net.Layout.PatternLayout, log4net">
       <conversionPattern value="%-5level %logger [%property{NDC}] -
%message%newline" />
     </layout>
   </appender>
   <appender name="EventLogAppender"
type="log4net.Appender.EventLogAppender" >
     <layout type="log4net.Layout.PatternLayout">
       <conversionPattern value="%date [%thread] %-5level %logger
[%property{NDC}] - %message%newline" />
     </layout>
   </appender>
   <root>
     <level value="ALL" />
     <appender-ref ref="UdpAppender" />
     <appender-ref ref="EventLogAppender" />
   </root>
 </log4net>
</configuration>

Here is the config for Chainsaw:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration >
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="true">
  <plugin name="UDPReceiver" class="org.apache.log4j.net.UDPReceiver">

  </plugin>
  <root>
     <level value="debug"/>
  </root>
</log4j:configuration>

Thanks in advance,
Byron


--
View this message in context: http://old.nabble.com/UpdAdapter-does-not-seem-to-be-working-tp33287879p33287879.html
Sent from the Log4net - Users mailing list archive at Nabble.com.



Gmane