public object Patch(string id, dynamic model)
        {
            LoggingId logId = new LoggingId(id);

            Site site = logId.SiteId == null ? null : SiteHelper.GetSite(logId.SiteId.Value);

            if (logId.SiteId != null && site == null)
            {
                Context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(null);
            }

            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            // Check for config_scope
            string configScope = model == null ? null : ManagementUnit.ResolveConfigScope(model);

            LoggingHelper.Update(model, _fileProvider, site, logId.Path, configScope);

            ManagementUnit.Current.Commit();

            return(LoggingHelper.ToJsonModel(site, logId.Path));
        }
        public object Get(string id)
        {
            LoggingId logId = new LoggingId(id);

            Site site = logId.SiteId == null ? null : SiteHelper.GetSite(logId.SiteId.Value);

            if (logId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            return(LoggingHelper.ToJsonModel(site, logId.Path));
        }
Beispiel #3
0
        public object Get(string id)
        {
            LoggingId logId = new LoggingId(id);

            Site site = logId.SiteId == null ? null : SiteHelper.GetSite(logId.SiteId.Value);

            if (logId.SiteId != null && site == null)
            {
                return(new StatusCodeResult((int)HttpStatusCode.NotFound));
            }

            return(LoggingHelper.ToJsonModel(site, logId.Path));
        }
        public void Delete(string id)
        {
            LoggingId logId = new LoggingId(id);

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;

            Site site = (logId.SiteId != null) ? SiteHelper.GetSite(logId.SiteId.Value) : null;

            if (site == null)
            {
                return;
            }

            var section = LoggingHelper.GetHttpLoggingSection(site, logId.Path, ManagementUnit.ResolveConfigScope());

            section.RevertToParent();

            ManagementUnit.Current.Commit();
        }
        public async Task Delete(string id)
        {
            LoggingId logId = new LoggingId(id);

            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;

            Site site = (logId.SiteId != null) ? SiteHelper.GetSite(logId.SiteId.Value) : null;

            if (site != null)
            {
                var section = LoggingHelper.GetHttpLoggingSection(site, logId.Path, ManagementUnit.ResolveConfigScope());
                section.RevertToParent();
                ManagementUnit.Current.Commit();
            }

            if (logId.SiteId == null && (LoggingHelper.IsHttpEnabled() || LoggingHelper.IsCustomEnabled()))
            {
                await LoggingHelper.SetFeatureEnabled(false);
            }
        }
Beispiel #6
0
        public override void Start()
        {
            Environment.Host.RouteBuilder.MapWebApiRoute(Defines.Resource.Guid, $"{Defines.PATH}/{{id?}}", new { controller = "logging" });

            Environment.Hal.ProvideLink(Defines.Resource.Guid, "self", logging => new { href = LoggingHelper.GetLocation(logging.id) });

            // Web Server
            Environment.Hal.ProvideLink(WebServer.Defines.Resource.Guid, Defines.Resource.Name, _ => {
                var id = new LoggingId(null, null, LoggingHelper.IsSectionLocal(null, null));
                return(new { href = LoggingHelper.GetLocation(id.Uuid) });
            });

            // Site
            Environment.Hal.ProvideLink(Sites.Defines.Resource.Guid, Defines.Resource.Name, site => {
                var siteId = new SiteId((string)site.id);
                Site s     = SiteHelper.GetSite(siteId.Id);
                var id     = new LoggingId(siteId.Id, "/", LoggingHelper.IsSectionLocal(s, "/"));
                return(new { href = LoggingHelper.GetLocation(id.Uuid) });
            });
        }
        internal static object ToJsonModel(Site site, string path)
        {
            LogSection         logSection     = GetLogSection(site, path);
            HttpLoggingSection httpLogSection = GetHttpLoggingSection(site, path);

            SiteLogFile logFile = null;

            if (site == null)
            {
                logFile = ManagementUnit.Current.ServerManager.SiteDefaults.LogFile;
            }
            else
            {
                logFile = site.LogFile;
            }

            LoggingId id = new LoggingId(site?.Id, path, httpLogSection.IsLocallyStored);

            Dictionary <string, bool> logTargetW3C = new Dictionary <string, bool>();

            if (logFile.Schema.HasAttribute(LogTargetW3CAttribute))
            {
                LogTargetW3C target = logFile.LogTargetW3C;

                logTargetW3C.Add("etw", target.HasFlag(LogTargetW3C.ETW));
                logTargetW3C.Add("file", target.HasFlag(LogTargetW3C.File));
            }

            FileLogFormat logFormat;

            if (logSection.CentralLogFileMode == CentralLogFileMode.Site)
            {
                logFormat = FromLogFormat(logFile.LogFormat);
            }
            else
            {
                logFormat = logSection.CentralLogFileMode == CentralLogFileMode.CentralBinary ? FileLogFormat.Binary : FileLogFormat.W3c;
            }


            bool logFilePerSite = logSection.CentralLogFileMode == CentralLogFileMode.Site;

            string directory    = default(string);
            string period       = default(string);
            long   truncateSize = default(long);
            bool   useLocalTime = default(bool);
            Dictionary <string, bool> logTargetW3c    = default(Dictionary <string, bool>);
            Dictionary <string, bool> logFields       = default(Dictionary <string, bool>);
            IEnumerable <object>      customLogFields = default(IEnumerable <object>);

            switch (logSection.CentralLogFileMode)
            {
            case CentralLogFileMode.CentralBinary:

                directory       = logSection.CentralBinaryLogFile.Directory;
                period          = PeriodRepresentation(logSection.CentralBinaryLogFile.Period);
                truncateSize    = logSection.CentralBinaryLogFile.TruncateSize;
                useLocalTime    = logSection.CentralBinaryLogFile.LocalTimeRollover;
                logTargetW3c    = null;
                logFields       = null;
                customLogFields = null;
                break;

            case CentralLogFileMode.CentralW3C:

                directory       = logSection.CentralW3CLogFile.Directory;
                period          = PeriodRepresentation(logSection.CentralW3CLogFile.Period);
                truncateSize    = logSection.CentralW3CLogFile.TruncateSize;
                useLocalTime    = logSection.CentralW3CLogFile.LocalTimeRollover;
                logTargetW3c    = null;
                logFields       = LogExtFileFlagsRepresentation(logSection.CentralW3CLogFile.LogExtFileFlags);
                customLogFields = null;

                break;

            case CentralLogFileMode.Site:

                directory    = logFile.Directory;
                period       = PeriodRepresentation(logFile.Period);
                truncateSize = logFile.TruncateSize;
                useLocalTime = logFile.LocalTimeRollover;
                logTargetW3c = logTargetW3C;
                logFields    = LogExtFileFlagsRepresentation(logFile.LogExtFileFlags);

                if (logFile.Schema.HasChildElement(CustomFieldsElement))
                {
                    customLogFields = logFile.CustomLogFields.Select(custField => {
                        return(new
                        {
                            field_name = custField.LogFieldName,
                            source_name = custField.SourceName,
                            source_type = SourceTypeRepresentation(custField.SourceType)
                        });
                    });
                }

                break;
            }

            dynamic o = new ExpandoObject();

            o.id    = id.Uuid;
            o.scope = site == null ? string.Empty : site.Name + path;

            // The metadata is obtained solely from <httpLogSection> because the <log> section is in applicationHost/* path which means it can't be accessed in web configs
            o.metadata = ConfigurationUtility.MetadataToJson(httpLogSection.IsLocallyStored, httpLogSection.IsLocked, httpLogSection.OverrideMode, httpLogSection.OverrideModeEffective);

            o.enabled      = IsLoggingEnabled(httpLogSection, logSection, logFile);
            o.log_per_site = logFilePerSite;

            o.directory         = directory;
            o.log_file_encoding = logSection.LogInUTF8 ? "utf-8" : "ansi";
            o.log_file_format   = Enum.GetName(typeof(FileLogFormat), logFormat).ToLower();

            if (logFile.Schema.HasAttribute(LogTargetW3CAttribute))
            {
                o.log_target = logTargetW3c;
            }

            o.log_fields = logFields;

            if (logFile.Schema.HasChildElement(CustomFieldsElement))
            {
                o.custom_log_fields = customLogFields;
            }

            o.rollover = new
            {
                period         = period,
                truncate_size  = truncateSize,
                use_local_time = useLocalTime,
            };

            o.website = SiteHelper.ToJsonModelRef(site);

            return(Core.Environment.Hal.Apply(Defines.Resource.Guid, o));
        }