log4net | Blog | Limilabs https://www.limilabs.com/blog Using Limilabs .net components Mon, 11 Mar 2024 09:29:43 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 Logging in Mail.dll email client https://www.limilabs.com/blog/logging-in-mail-dll Mon, 01 Aug 2016 16:03:54 +0000 http://www.limilabs.com/blog/?p=1478 This article provides a comprehensive guide on how to perform logging within the Mail.dll .NET email client. It outlines step-by-step instructions for implementing robust logging mechanisms, enhancing troubleshooting capabilities, and tracking email communication effectively. By following the methods detailed in the article, VisualBasic and C# developers can seamlessly integrate logging features into their applications, gaining […]

The post Logging in Mail.dll email client first appeared on Blog | Limilabs.

]]>
This article provides a comprehensive guide on how to perform logging within the Mail.dll .NET email client. It outlines step-by-step instructions for implementing robust logging mechanisms, enhancing troubleshooting capabilities, and tracking email communication effectively.

By following the methods detailed in the article, VisualBasic and C# developers can seamlessly integrate logging features into their applications, gaining valuable insights into the Imap, Pop3 and Smtp clients behavior and facilitating streamlined debugging processes.

To enable logging for all Mail.dll .NET clients (Imap, Pop3, Smtp) you only need to add the following line before you connect:

// C# version:

Limilabs.Mail.Log.Enabled = true;
' VB.NET version:

Limilabs.Mail.Log.Enabled = True

You can observe the log output by:

  • looking at the Visual Studio’s output window (View/Output/’Show output from’: Debug)
  • subscribing to Log.WriteLine event
  • defining custom listeners using your application’s config file (App.config or Web.config)
  • using log4net

This is how the log looks like in the Visual Studio’s output window:

For regular .NET framework you can also enable logging using your application’s config file (App.config, Web.config):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.diagnostics>

      <switches>
        <add name="Mail.dll" value="Verbose" />
      </switches>

    </system.diagnostics>
</configuration>

Logging with log4net

If you are using log4net, Mail.dll is going to use log4net instead of standard .NET System.Net.TraceSource class. Please refer to log4net manual on how to capture log entries.

Mail.dll uses logger called “Mail.dll”

_logger = LogManager.GetLogger("Mail.dll")

and level Info _logger.Info(message) to log information.

Please remember that even when using log4net, you need to enable logging by setting “Limilabs.Mail.Log.Enabled = True” or by setting Mail.dll trace switch in the config file (App.config, Web.config) to Verbose as shown above.

Log.WriteLine

Limilabs.Mail.Log class exposes WriteLine event. You can use that event to subscribe your own logging library in both .NET and .NET framework.

// C#

Limilabs.Mail.Log.WriteLine += Console.WriteLine;
' VB.NET

AddHandler Limilabs.Mail.Log.WriteLine, AddressOf Console.WriteLine

Log to file (.NET framework)

You’ll need to define a TextWriterTraceListener that writes to a file and connect it with Mail.dll trace source. The easiest solution is to modify your application’s config file App.config or Web.config accordingly:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.diagnostics>

        <trace autoflush="true"/>

        <switches>
            <add name="Mail.dll" value="Verbose"/>
        </switches>

        <sources>
            <source name="Mail.dll">
                <listeners>
                    <add name="MailLogFile"/>
                </listeners>
            </source>
        </sources>

        <sharedListeners>
            <add
                name="MailLogFile"
                type="System.Diagnostics.TextWriterTraceListener"
                initializeData="c:\folder-with-write-access\mail.log"/>
        </sharedListeners>

    </system.diagnostics>
</configuration>

The post Logging in Mail.dll email client first appeared on Blog | Limilabs.

]]>
I have problems issuing IMAP, POP3 or SMTP command https://www.limilabs.com/blog/i-have-problems-issuing-imap-pop3-smtp-command https://www.limilabs.com/blog/i-have-problems-issuing-imap-pop3-smtp-command#comments Wed, 05 Jan 2011 14:51:44 +0000 http://www.limilabs.com/blog/?p=1734 Mail.dll is a rock solid product, however most email servers don’t follow RFC specifications rigorously. In the following few steps we’ll help you gather the information we need to make Mail.dll IMAP and POP3 clients better. If you have problems parsing a message please go here. Prerequisites First please check if you have the latest […]

The post I have problems issuing IMAP, POP3 or SMTP command first appeared on Blog | Limilabs.

]]>
Mail.dll is a rock solid product, however most email servers don’t follow RFC specifications rigorously. In the following few steps we’ll help you gather the information we need to make Mail.dll IMAP and POP3 clients better.

If you have problems parsing a message please go here.

Prerequisites

First please check if you have the latest version installed. You can always download the latest version of Mail.dll email component and release notes here.

Identify command

Please identify the command/set of commands that cause problems.

Turn on logging

Enable logging for Mail.dll clients:

// C# version:

Log.Enabled = true;

' VB.NET version:

Log.Enabled = True

You can observe standard Visual Studio’s trace output window (View/Output/Show output from: Debug) or add a custom listener to Trace.Listeners collection.

You can also enable logging using App.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.diagnostics>
      <switches>
        <add name="Mail.dll" value="True" />
      </switches>
    </system.diagnostics>
</configuration>

log4net

If you are using the latest version of log4net.dll, Mail.dll is going to use log4net instead of Trace class. Please refer to log4net manual on how to capture log entries.

Please remember that even when using log4net, you need to enable logging by setting “Limilabs.Mail.Log.Enabled = True” or be setting Mail.dll boolean switch in App.config file.

Log to file

You can create your custom TraceListener that writes log to file:

// C# version:

internal class MyListener : TextWriterTraceListener
{
    public MyListener(string fileName)
        : base(fileName)
    {
    }

    public override void Write(string message, string category)
    {
        if (category == "Mail.dll")
            base.Write(message, category);
    }

    public override void WriteLine(string message, string category)
    {
        if (category == "Mail.dll")
            base.WriteLine(message, category);
    }
}
' VB.NET version

Friend Class MyListener
	Inherits TextWriterTraceListener
	Public Sub New(fileName As String)
		MyBase.New(fileName)
	End Sub

	Public Overrides Sub Write(message As String, category As String)
		If category = "Mail.dll" Then
			MyBase.Write(message, category)
		End If
	End Sub

	Public Overrides Sub WriteLine(message As String, category As String)
		If category = "Mail.dll" Then
			MyBase.WriteLine(message, category)
		End If
	End Sub
End Class

…then add it to Listeners collection:

// C# version:

Log.Enabled = true;
Trace.Listeners.Add(new MyListener(@"c:/mail_log.txt"));
Trace.AutoFlush = true;

' VB.NET version:

Log.Enabled = True
Trace.Listeners.Add(New MyListener("c:/mail_log.txt"))
Trace.AutoFlush = True

Log.WriteLine

Log class exposes WriteLine event. You can use that event to subscribe your own logging library:

// C#

Log.WriteLine += Console.WriteLine;
' VB.NET

Log.WriteLine += Console.WriteLine

Reproduce the problem

Perform the operations that cause problems, and save the log to file.
You can remove username and password, but please do not modify the file extensively. If you do, it may be impossible to reproduce the issue.
In particular do not change new line format nor encoding.

Additional information

Please answer following questions:

  • What exception are you getting?
  • What is the exception stack trace?
  • What is the exception message?
  • What result you expect?
  • What result are you getting?
  • Which .NET Framework version are you using?
  • Is it console, windows forms, windows service or web application?
  • If it is possible please attach the source code you are using

Contact Limilabs support 

Finally please zip the log file and send it as an attachment, along with all the answers to: .

Thank you!

The post I have problems issuing IMAP, POP3 or SMTP command first appeared on Blog | Limilabs.

]]>
https://www.limilabs.com/blog/i-have-problems-issuing-imap-pop3-smtp-command/feed 1
Logging in Ftp.dll https://www.limilabs.com/blog/logging-in-ftp-dll Fri, 05 Nov 2010 16:51:27 +0000 http://www.limilabs.com/blog/?p=1487 To enable logging for Ftp.dll .NET FTP and FTPS component you only need to add the following line before you connect: You can observe the log output by: looking at the Visual Studio’s output window (View/Output/’Show output from’: Debug) subscribing to Log.WriteLine event defining custom listeners using your application’s config file (App.config or Web.config) using […]

The post Logging in Ftp.dll first appeared on Blog | Limilabs.

]]>
To enable logging for Ftp.dll .NET FTP and FTPS component you only need to add the following line before you connect:

// C# version:

Limilabs.FTP.Log.Enabled = true;

' VB.NET version:

Limilabs.FTP.Log.Enabled = True

You can observe the log output by:

  • looking at the Visual Studio’s output window (View/Output/’Show output from’: Debug)
  • subscribing to Log.WriteLine event
  • defining custom listeners using your application’s config file (App.config or Web.config)
  • using log4net

This is how the log looks like in the Visual Studio’s output window:

You can also enable logging using your application’s config file (App.config, Web.config):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.diagnostics>

      <switches>
        <add name="Ftp.dll" value="Verbose" />
      </switches>

    </system.diagnostics>
</configuration>

log4net

If you are using the latest version of log4net.dll, Ftp.dll is going to use log4net instead of standard .NET System.Net.TraceSource class. Please refer to log4net manual on how to capture log entries.

Ftp.dll uses logger called “Ftp.dll” (_logger = LogManager.GetLogger(“Ftp.dll”)) and level Info (_logger.Info(message)) to log information.

Please remember that even when using log4net, you need to enable logging by setting “Limilabs.FTP.Log.Enabled = True” or by setting Ftp.dll trace switch in the config file (App.config, Web.config) to Verbose as shown above.

Log to file

You’ll need to define a TextWriterTraceListener that writes to a file and connect it with Ftp.dll trace source. The easiest solution is to modify your application’s config file (App.config, Web.config) accordingly:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.diagnostics>

        <trace autoflush="true"/>
   
        <switches>
            <add name="Ftp.dll" value="Verbose"/>
        </switches>
   
        <sources>
            <source name="Ftp.dll">
                <listeners>
                    <add name="FtpLogFile"/>
                </listeners>
            </source>
        </sources>
   
        <sharedListeners>
            <add 
                name="FtpLogFile" 
                type="System.Diagnostics.TextWriterTraceListener" 
                initializeData="c:\folder-with-write-access\ftp.log"/>
        </sharedListeners>

    </system.diagnostics>
</configuration>

Log.WriteLine

Log class exposes WriteLine event. You can use that event to subscribe your own logging library.

// C#

Limilabs.FTP.Log.WriteLine += Console.WriteLine;
' VB.NET

Limilabs.FTP.Log.WriteLine += Console.WriteLine

You can download Ftp.dll FTP/FTPS client for .NET here.

The post Logging in Ftp.dll first appeared on Blog | Limilabs.

]]>
Programmatically check Log4Net log https://www.limilabs.com/blog/programmatically-check-log4net https://www.limilabs.com/blog/programmatically-check-log4net#comments Mon, 30 Nov 2009 10:16:49 +0000 http://www.limilabs.com/blog/?p=308 Today I needed to create unit test that checked if the NHibernate query was generated optimally. Good thing is that, in case of an inefficient query, NHibernate puts a warning using log4net: log.Warn( "firstResult/maxResults specified with collection fetch; applying in memory!" ); I wanted something like this: [Test] public void FindUsersBy_QueryWithLimit_LimitsOnSQLSide() { using (LogChecker logChecker […]

The post Programmatically check Log4Net log first appeared on Blog | Limilabs.

]]>
Today I needed to create unit test that checked if the NHibernate query was generated optimally.

Good thing is that, in case of an inefficient query, NHibernate puts a warning using log4net:

log.Warn( "firstResult/maxResults specified with collection fetch; applying in memory!" );

I wanted something like this:

[Test]
public void FindUsersBy_QueryWithLimit_LimitsOnSQLSide()
{
    using (LogChecker logChecker
        = new LogChecker("NHibernate", Level.Warn))
    {
        // Execute query using NHibernate

        // ....

        Assert.IsEmpty(logChecker.Messages);
    }
}

The problem is that it’s not that easy to attach MemoryAppender for a duration of unit test to the specified logger.

Anyway here’s the code:

public class LogChecker : IDisposable
{
    readonly Logger _logger;
    readonly Level _previousLevel;
    readonly MemoryAppender _appender = new MemoryAppender();

    public LogChecker(string logName, Level levelToCheck)
    {
        _logger = (Logger)LogManager.GetLogger(logName).Logger;
        _logger.AddAppender(_appender);
        _previousLevel = _logger.Level;
        _logger.Level = levelToCheck;
    }

    public List<string> Messages
    {
        get
        {
            return new List<loggingEvent>(_appender.GetEvents())
                  .ConvertAll(x => x.RenderedMessage);
        }
    }

    public void Dispose()
    {
        _logger.Level = _previousLevel;
        _logger.RemoveAppender(_appender);
    }
};

The post Programmatically check Log4Net log first appeared on Blog | Limilabs.

]]>
https://www.limilabs.com/blog/programmatically-check-log4net/feed 4