public void LoggingExtensions_Test1()
        {
            log.DebugFormat("Time now is {0:S}", DateTime.Now.ToString());
            log.InfoFormat("Time now is {0:S}", DateTime.Now.ToString());
            log.WarnFormat("Time now is {0:S}", DateTime.Now.ToString());
            log.ErrorFormat("Time now is {0:S}", DateTime.Now.ToString());
            log.FatalFormat("Time now is {0:S}", DateTime.Now.ToString());

            log.TraceFormat("Time now is {0:S}", DateTime.Now.ToString());
            log.VerboseFormat("Time now is {0:S}", DateTime.Now.ToString());
        }
示例#2
0
        // TODO: Support object update
        protected virtual IHttpActionResult _PostInternal(T value)
        {
            if (value == null)
            {
                return(BadRequest());
            }

            log.VerboseFormat("_PostInternal::{0:S}({1:S}) requested", typeof(T).Name, value.ToString());

            try
            {
                using (SqlConnection conn = new SqlConnection(Startup.ConnectionString))
                {
                    conn.Open();
                    using (var trans = conn.BeginTransaction())
                    {
                        DatabaseItem <K> item = default(DatabaseItem <K>);

                        if (value.HasValidID())
                        {
                            item = DatabaseItem <K> .GetByID <T>(conn, trans, value.ID);
                        }

                        if (item == null)
                        {
                            #region New item
                            var ret = value.Clone <T>(conn, trans);
                            ret.Validate();
                            trans.Commit();
                            // TODO : return a valid URI
                            return(Created("", ret));

                            #endregion
                        }
                        else
                        {
                            #region Update
                            value.ID = item.ID;
                            DatabaseItem <K> .Update <T>(conn, trans, value);

                            trans.Commit();

                            return(Ok(value));

                            #endregion
                        }
                    }
                }
            }
            catch (Core.Exceptions.TaskNotFoundException tfe)
            {
                log.ErrorFormat("TaskNotFoundException processing {0:S} POST: {1:S}", typeof(T).Name, tfe.ToString());
                return(BadRequest());
            }
            catch (System.Exception exce)
            {
                log.ErrorFormat("Unhandled exception processing {0:S} POST: {1:S}", typeof(T).Name, exce.ToString());

                return(InternalServerError(exce));
            }
        }