private void WriteCrashToFile(string text)
        {
            if (_useLog)
            {
                if (!Directory.Exists(_logPath))
                {
                    Directory.CreateDirectory(_logPath);
                }
                string filenameTxt = string.Format("{0}__{1}.txt", Path.Combine(_logPath, _appName),
                                                   DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss"));
                using (TextWriter logtoFile = new StreamWriter(filenameTxt))
                {
                    logtoFile.WriteLine("[{0}]", _appName);
                    logtoFile.WriteLine("Date={0}", DateTime.Now);
                    logtoFile.WriteLine("Application={0} {1}", Application.ProductName, Application.ProductVersion);
                    logtoFile.WriteLine("ExecutablePath={0}", Application.ExecutablePath);
                    logtoFile.WriteLine("Company={0}", Application.CompanyName);
                    logtoFile.WriteLine();
                    if (!string.IsNullOrEmpty(_prefixText))
                    {
                        logtoFile.WriteLine(_prefixText);
                        logtoFile.WriteLine();
                    }
                    logtoFile.WriteLine("########################");
                    logtoFile.WriteLine("##        Error       ##");
                    logtoFile.WriteLine("########################");
                    logtoFile.WriteLine("[Error]");
                    logtoFile.WriteLine(text);
                    logtoFile.WriteLine();
                    logtoFile.WriteLine();
                    logtoFile.WriteLine("########################");
                    logtoFile.WriteLine("## System Information ##");
                    logtoFile.WriteLine("########################");
                    logtoFile.WriteLine("[System]");
                    logtoFile.WriteLine("OperativeSystem={0}", SystemInformationEx.GetOSName(true, true));
                    logtoFile.WriteLine("ProcessorCount={0}", SystemInformationEx.GetProcessorCount());
                    logtoFile.WriteLine();
                    logtoFile.WriteLine();
                    logtoFile.WriteLine("########################");
                    logtoFile.WriteLine("##     Open Forms     ##");
                    logtoFile.WriteLine("########################");
                    logtoFile.WriteLine("[Forms]");
                    for (int i = 0; i < Application.OpenForms.Count; i++)
                    {
                        //Type frmtype = typeof(Application.OpenForms[i]);
                        logtoFile.WriteLine("Form{0}={1}", i + 1, Application.OpenForms[i]);
                    }
                    logtoFile.WriteLine();
                    logtoFile.WriteLine();
                    logtoFile.WriteLine("########################");
                    logtoFile.WriteLine("## Loaded Assemblies  ##");
                    logtoFile.WriteLine("########################");

                    /*logtoFile.Write("[{1}]{0}Date={3}{0}{2}{0}{0}{4}{0}{0}########################{0}## System Information: ##{0}########################{0}{0}{0}########################{0}## Loaded Assemblies: ##{0}########################{0}",
                     *  Environment.NewLine,
                     *  _appName,
                     *  _prefixText,
                     *  DateTime.Now,
                     *  text);*/
                    Assembly[] assemblies = AssemblyEx.GetLoadedAssemblies();
                    for (int i = 0; i < assemblies.Length; i++)
                    {
                        logtoFile.WriteLine("[{1}]{0}   Location={2}{0}", Environment.NewLine, assemblies[i].FullName, assemblies[i].Location);
                    }
                    if (!string.IsNullOrEmpty(_suffixText))
                    {
                        logtoFile.WriteLine(_suffixText);
                    }
                    logtoFile.Close();
                }
            }
            if (_useDump && Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                if (!Directory.Exists(_dumpPath))
                {
                    Directory.CreateDirectory(_dumpPath);
                }
                MiniDump.MiniDumpToFile(string.Format("{0}__{1}.dmp", Path.Combine(_dumpPath, _appName),
                                                      DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")));
            }
            //return string.Format("{0}{1}", AppCrashLogs, filename);
        }
        /// <summary>
        /// Writes a crash to file, including dump creation.
        /// </summary>
        /// <param name="ex">Exception value.</param>
        private void WriteCrashToFile(Exception ex)
        {
            if (_useLog)
            {
                if (!Directory.Exists(_logPath))
                {
                    Directory.CreateDirectory(_logPath);
                }
                string filenameTxt = string.Format("{0}__{1}.txt", Path.Combine(_logPath, _appName),
                                                   DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss"));
                using (TextWriter logtoFile = new StreamWriter(filenameTxt))
                {
                    logtoFile.WriteLine("[{0}]", _appName);
                    logtoFile.WriteLine("Date={0}", DateTime.Now);
                    logtoFile.WriteLine("Application={0} {1}", Application.ProductName, Application.ProductVersion);
                    logtoFile.WriteLine("ExecutablePath={0}", Application.ExecutablePath);
                    logtoFile.WriteLine("Company={0}", Application.CompanyName);
                    logtoFile.WriteLine();
                    if (!string.IsNullOrEmpty(_prefixText))
                    {
                        logtoFile.WriteLine(_prefixText);
                        logtoFile.WriteLine();
                    }
                    logtoFile.WriteLine("########################");
                    logtoFile.WriteLine("##        Error       ##");
                    logtoFile.WriteLine("########################");
                    //logtoFile.WriteLine("[Error]");
                    int       count     = 1;
                    Exception exception = ex;
                    while (exception != null)
                    {
                        logtoFile.WriteLine("[Exception{0}]", count);
                        logtoFile.WriteLine("Message={0}", exception.Message);
                        //StackTrace stackTrace = new StackTrace(exception);

                        /*for (int x = 0; x < stackTrace.FrameCount; x++)
                         * {
                         *  StackFrame stackFrame = stackTrace.GetFrame(x);
                         *  MethodBase methodBase = stackFrame.GetMethod();
                         *  logtoFile.WriteLine("StackFrame{0}={1}", x + 1, stackFrame);
                         *  logtoFile.WriteLine("MethodBase{0}={1}", x + 1, methodBase);
                         * }*/
                        foreach (DictionaryEntry data in exception.Data)
                        {
                            logtoFile.WriteLine("{0}={1}", data.Key, data.Value);
                        }
                        logtoFile.WriteLine("StackTrace={0}", exception.StackTrace);
                        logtoFile.WriteLine("TargetSite={0}", exception.TargetSite);
                        logtoFile.WriteLine("Source={0}", exception.Source);
                        logtoFile.WriteLine("HelpLink={0}", exception.HelpLink);
                        count++;
                        exception = exception.InnerException;
                        logtoFile.WriteLine();
                    }
                    logtoFile.WriteLine();
                    logtoFile.WriteLine();
                    logtoFile.WriteLine("########################");
                    logtoFile.WriteLine("## System Information ##");
                    logtoFile.WriteLine("########################");
                    logtoFile.WriteLine("[System]");
                    logtoFile.WriteLine("OperativeSystem={0}", SystemInformationEx.GetOSName(true, true));
                    logtoFile.WriteLine("ProcessorCount={0}", SystemInformationEx.GetProcessorCount());
                    logtoFile.WriteLine();
                    logtoFile.WriteLine();
                    logtoFile.WriteLine("########################");
                    logtoFile.WriteLine("##     Open Forms     ##");
                    logtoFile.WriteLine("########################");
                    logtoFile.WriteLine("[Forms]");
                    for (int i = 0; i < Application.OpenForms.Count; i++)
                    {
                        //Type frmtype = typeof(Application.OpenForms[i]);
                        logtoFile.WriteLine("Form{0}={1}", i + 1, Application.OpenForms[i]);
                    }
                    logtoFile.WriteLine();
                    logtoFile.WriteLine();
                    logtoFile.WriteLine("########################");
                    logtoFile.WriteLine("## Loaded Assemblies  ##");
                    logtoFile.WriteLine("########################");

                    /*logtoFile.Write("[{1}]{0}Date={3}{0}{2}{0}{0}{4}{0}{0}########################{0}## System Information: ##{0}########################{0}{0}{0}########################{0}## Loaded Assemblies: ##{0}########################{0}",
                     *  Environment.NewLine,
                     *  _appName,
                     *  _prefixText,
                     *  DateTime.Now,
                     *  text);*/
                    Assembly[] assemblies = AssemblyEx.GetLoadedAssemblies();
                    for (int i = 0; i < assemblies.Length; i++)
                    {
                        logtoFile.WriteLine("[{1}]{0}   Location={2}{0}", Environment.NewLine, assemblies[i].FullName, assemblies[i].Location);
                    }
                    if (!string.IsNullOrEmpty(_suffixText))
                    {
                        logtoFile.WriteLine(_suffixText);
                    }
                    logtoFile.Close();
                }
            }
            if (_useDump && Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                if (!Directory.Exists(_dumpPath))
                {
                    Directory.CreateDirectory(_dumpPath);
                }
                MiniDump.MiniDumpToFile(string.Format("{0}__{1}.dmp", Path.Combine(_dumpPath, _appName),
                                                      DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")));
            }
            //return string.Format("{0}{1}", AppCrashLogs, filename);
        }