Thinktecture.Tools.Web.Services.ContractFirst.AppLog.LogMessage C# (CSharp) Method

LogMessage() public static method

public static LogMessage ( string message ) : void
message string
return void
        public static void LogMessage(string message)
        {
            string t = WscfConfiguration.AppSettings["trace"];

            if ((t != null) && (t == "1" || t.ToLower() == "true"))
            {
                Mutex flock = null;
                try
                {
                    flock = new Mutex(false, "WSCFLOG");

                    if (flock.WaitOne())
                    {

                        string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                        string logFile = directory + "\\" + "WSCF.log";
                        StreamWriter writer = new StreamWriter(logFile, true, Encoding.UTF8);
                        writer.WriteLine(DateTime.Now.ToString("M-dd-yyyy H:mm"));
                        writer.WriteLine(message);
                        writer.WriteLine();
                        writer.Close();
                    }
                }
                catch (Exception ex)
                {
                    EventLog.WriteEntry("WSCF Log",
                        string.Format("An error occrred while trying to write the message {0} to the log. Details: {1}",
                        message, ex.Message), EventLogEntryType.Error);
                }
                finally
                {
                    if (flock != null)
                    {
                        flock.ReleaseMutex();
                    }
                }
            }
        }

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        ///      Implements the QueryStatus method of the IDTCommandTarget interface.
        ///      This is called when the command's availability is updated
        /// </summary>
        /// <param term='commandName'>
        ///		The name of the command to determine state for.
        /// </param>
        /// <param term='neededText'>
        ///		Text that is needed for the command.
        /// </param>
        /// <param term='status'>
        ///		The state of the command in the user interface.
        /// </param>
        /// <param term='commandText'>
        ///		Text requested by the neededText parameter.
        /// </param>
        /// <seealso class='Exec' />
        public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText)
        {
            AppLog.LogMessage("Entering QueryStatus method.");

            try
            {
                status = vsCommandStatus.vsCommandStatusInvisible;
                if (commandName == MenuBuilder.MenuEditWsdl)
                {
                    status = QueryStatusForEditWsdl();
                }

                if (commandName == MenuBuilder.MenuWscfContextMenu)
                {
                    status = QueryStatusForContextMenu();
                }

                if (commandName == MenuBuilder.MenuCreateWsdl)
                {
                    status = QueryStatusForCreateWsdl();
                }

                if (commandName == MenuBuilder.MenuGenerateDataContracts)
                {
                    status = QueryStatusForGenDC();
                }

                if (neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
                {
                    if (commandName == MenuBuilder.MenuWscfContextMenu2)
                    {
                        status = (vsCommandStatus)vsCommandStatus.vsCommandStatusEnabled |
                                 vsCommandStatus.vsCommandStatusSupported;
                        AppLog.LogMessage("WSCF menu 2 command is enabled");
                    }
                    if (commandName == MenuBuilder.MenuWscf)
                    {
                        status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported |
                                 vsCommandStatus.vsCommandStatusEnabled;
                        AppLog.LogMessage("Contract first command is enabled");
                    }
                    if (commandName == MenuBuilder.MenuPasteXmlAsSchema)
                    {
                        status = vsCommandStatus.vsCommandStatusSupported;
                        if (visualStudio.SelectedProject != null)
                        {
                            status = vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                            AppLog.LogMessage("Paste Schema command is enabled");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                AppLog.LogMessage(ex.Message);
                throw;
            }

            AppLog.LogMessage("Leaving QueryStatus method.");
        }
All Usage Examples Of Thinktecture.Tools.Web.Services.ContractFirst.AppLog::LogMessage