Skip to content

Instantly share code, notes, and snippets.

@johnmmoss
Last active July 18, 2019 11:07
Show Gist options
  • Select an option

  • Save johnmmoss/3486c43c43e13ab16c0d83bd7c128748 to your computer and use it in GitHub Desktop.

Select an option

Save johnmmoss/3486c43c43e13ab16c0d83bd7c128748 to your computer and use it in GitHub Desktop.
public class LogController : ApiController
{
public log4net.Repository.Hierarchy.Hierarchy LogHierarchy
{
get
{
return (log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository();
}
}
// LogManager.GetRepository().LevelMap[logLevel]
[HttpPost]
public IHttpActionResult Level(string level)
{
try
{
var log4netLogLevel = LogHierarchy.LevelMap[level] ?? log4net.Core.Level.All;
LogHierarchy.Root.Level = log4netLogLevel;
LogHierarchy.RaiseConfigurationChanged(EventArgs.Empty);
}
catch (Exception ex)
{
return InternalServerError(ex);
}
return Ok();
}
[HttpGet]
public IHttpActionResult Level()
{
return Ok(LogHierarchy.Root.Level.ToString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment