-----------------------------------

Acquista i software ArcGIS tramite Studio A&T srl, rivenditore autorizzato dei prodotti Esri.

I migliori software GIS, il miglior supporto tecnico!

I migliori software GIS, il miglior supporto tecnico!
Azienda operante nel settore GIS dal 2001, specializzata nell’utilizzo della tecnologia ArcGIS e aderente ai programmi Esri Italia Business Network ed Esri Partner Network

-----------------------------------



lunedì 15 dicembre 2008

EMAB (Logger)

I have used EMAB for simplification ( EMAB download )
for this project.

Nevertheless now it has been overcome by Enterprise Library 4.1 ( Enterprise Library 4.1 download )

For details see Best practises Microsoft


App.Config:


<?xml version="1.0"?>

<configuration>

 

 

 

 

  <configSections>

    <section name="exceptionManagement" type="Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManagerSectionHandler,Microsoft.ApplicationBlocks.ExceptionManagement" />

  </configSections>

 

 

  <exceptionManagement mode="on">

    <publisher assembly="MapControlEMAB" type="Studioat.ArcEngine.AppBase.Classes.EM" fileName="LogError.txt" sendEMail="off" operatorMail="xxxx@gmail.it" operatorFrom="xxxx@yahoo.it" subject="Logger MapControlEMAB"  host="smtp.mail.yahoo.it" user="" password=""/>

  </exceptionManagement>

 

</configuration>




mode="on|off" enable/disable log
assembly="MapControlEMAB" assembly which holds the custom class to manage log
type="Studioat.ArcEngine.AppBase.Classes.EM" custom class to manage log
fileName="LogError.txt" name of the log file created in bin

sendEMail="on|off" enable/disable log on email
operatorMail="xxxx@gmail.it" mail to
operatorFrom="xxxx@yahoo.it" mail from
subject="Logger MapControlEMAB" subject
host="smtp.mail.yahoo.it" smtp
user="" authentication user mail
password="" authentication password mail


From menu select 'Demo Log':

In this sample the error is in the log:

try

            {

                int a = 1, b = 0, c;

 

                c = a / b;

 

            }

            catch (Exception ex)

            {

 

                ExceptionManager.Publish(ex);

 

            }

            finally

            {

 

                MessageBox.Show("See new entry in LogError.txt", "Logger");

 

            }




In this sample the error is in the log plus your extra information:

try

            {

                int a = 1, b = 0, c;

 

                c = a / b;

 

            }

            catch (Exception ex)

            {

 

                NameValueCollection nvc = new NameValueCollection();

                nvc.Add("Info", "My comments bla bla bla:\n\n");

                ExceptionManager.Publish(ex, nvc);

 

 

            }

            finally

            {

 

                MessageBox.Show("See new entry in LogError.txt", "Logger");

 

            }




In this sample the error without handling Exception (remember that to see this error you can't be in debug but you must run directly exe.)


int a = 1, b = 0, c;

 

            c = a / b;





In form main we set UnhandledException for unhandling errors

/// <summary>

    /// The main entry point for the application.

    /// </summary>

    [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)]

    [STAThread]

    static void Main()

    {

 

 

        #region manager error

        Application.ThreadException += new ThreadExceptionEventHandler(frmMain.UIThreadException);

        Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

 

 

        AppDomain.CurrentDomain.UnhandledException +=

            new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

        #endregion manager error

 

 

        Application.Run(new frmMain());

    }

    #region manager error

    private static void UIThreadException(object sender, ThreadExceptionEventArgs t)

    {

        DialogResult result = DialogResult.Cancel;

        try

        {

            result = ShowThreadExceptionDialog("Error", t.Exception);

        }

        catch (Exception ex)

        {

            try

            {

                MessageBox.Show("Error", "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop);

                ExceptionManager.Publish(ex);

            }

            finally

            {

                Application.Exit();

            }

        }

 

 

        if (result == DialogResult.Abort)

            Application.Exit();

    }

    private static DialogResult ShowThreadExceptionDialog(string title, Exception e)

    {

        string errorMsg = "Contact admin with following info:\n\n";

        errorMsg += e.Message + "\n\nStack Trace:\n" + e.StackTrace;

        return MessageBox.Show(errorMsg, title, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop);

    }

    private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)

    {

        try

        {

            Exception ex = (Exception)e.ExceptionObject;

 

 

            NameValueCollection nvc = new NameValueCollection();

            nvc.Add("Info", "Contact admin with these info errors:\n\n");

            ExceptionManager.Publish(ex, nvc);

 

 

        }

        catch (Exception exc)

        {

            try

            {

 

                ExceptionManager.Publish(exc);

            }

            finally

            {

                Application.Exit();

            }

        }

    }

    #endregion manager error





class EM inherits from IExceptionPublisher and is the custom class used for the logger.



Here you can download the soluzion VS2008 Logger Error

Nessun commento: