本文整理汇总了C#中Serilog.LoggerConfiguration.Warning方法的典型用法代码示例。如果您正苦于以下问题:C# LoggerConfiguration.Warning方法的具体用法?C# LoggerConfiguration.Warning怎么用?C# LoggerConfiguration.Warning使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Serilog.LoggerConfiguration
的用法示例。
在下文中一共展示了LoggerConfiguration.Warning方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
//Configuration by AppSettings
var logger = new LoggerConfiguration()
.ReadFrom.AppSettings()
.MinimumLevel.Debug()
.Enrich.WithThreadId()
.Enrich.WithProperty("MyMetaProperty", "Oh! the beautiful value!")
.WriteTo.ColoredConsole()
.CreateLogger();
////Configuration by code
//var logger = new LoggerConfiguration()
// .MinimumLevel.Debug()
// .Enrich.WithThreadId()
// .Enrich.WithProperty("MyMetaProperty", "Oh! the beautiful value!")
// .WriteTo.ColoredConsole()
// .WriteTo.BrowserConsole(port: 9999, buffer: 50)
// .CreateLogger();
OpenBrowserToBrowserLogUrl();
logger.Information("Hello!");
Thread.Sleep(1000);
for (int i = 0; i < 100000; i++)
{
logger.Information("Hello this is a log from a server-side process!");
Thread.Sleep(100);
logger.Warning("Hello this is a warning from a server-side process!");
logger.Debug("... and here is another log again ({IndexLoop})", i);
Thread.Sleep(200);
try
{
ThrowExceptionWithStackTrace(4);
}
catch (Exception ex)
{
logger.Error(ex, "An error has occured, really?");
}
Thread.Sleep(1000);
}
}
示例2: AuthorizeCore
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
bool disableAuthentication = false;
GenericIdentity identity;
GenericPrincipal principal;
string[] roles;
#if DEBUG
disableAuthentication = true;
#endif
if (disableAuthentication)
{
// Create a fake user and use this in debugging to disable authentication.
identity = new GenericIdentity("alongoria");
roles = new string[] { "admin" };
principal = new GenericPrincipal(identity, roles);
httpContext.User = principal;
}
else
{
HttpCookie authCookie = httpContext.Request.Cookies[FormsAuthentication.FormsCookieName];
if (authCookie != null)
{
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
string username = authTicket.Name;
// According to many articles and Ninject docs like:
// https://github.com/ninject/Ninject.Web.Mvc/wiki/Filters-and-Scoped,
// https://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=98,
// https://stackoverflow.com/questions/29915192/unity-property-injection-on-authorizeattribute
// MVC caches filters, which means dependency injection with .InRequestScope() does not work.
// If we try to inject the _authorizationFilter with Ninject, there is a runtime error saying the DbContext has been disposed
// on the second and all subsequent requests (works fine on the first request).
using (_userService = new UserService())
{
User user = _userService.GetByUsername(username);
if (user == null)
{
// The user has a cookie, so they are in the Active Directory.
// But they aren't in our local database (new employee, probably), so add them.
User newUser = new User()
{
Username = username,
IsActive = true,
IsAdmin = false
};
HttpCookie initialsCookie = httpContext.Request.Cookies[Configuration.GetAppSetting("UserInitialsCookieName")];
if (initialsCookie != null && !string.IsNullOrWhiteSpace(initialsCookie.Value))
{
newUser.Initials = initialsCookie.Value;
}
else
{
if (username.Length > 1)
newUser.Initials = username.Substring(0, 2);
else
newUser.Initials = "xx";
}
_userService.Insert(newUser);
user = _userService.GetByUsername(username);
using (var log = new LoggerConfiguration().ReadFrom.AppSettings().CreateLogger())
{
log.Information("A new user was added to the application: {0}", username);
}
} // End inserting new User and pulling it from the db.
else
{
// If there's a cookie with initials, check its value to make sure our db value isn't out of date.
HttpCookie initialsCookie = httpContext.Request.Cookies[Configuration.GetAppSetting("UserInitialsCookieName")];
if (initialsCookie != null && !string.IsNullOrWhiteSpace(initialsCookie.Value))
{
if (!initialsCookie.Value.Equals(user.Initials, System.StringComparison.CurrentCultureIgnoreCase))
{
user.Initials = initialsCookie.Value;
_userService.Update(user);
}
}
}
if (!user.IsActive)
{
using (var log = new LoggerConfiguration().ReadFrom.AppSettings().CreateLogger())
{
log.Warning("A user whose account was disabled attempted to log on to the application: {0}", username);
}
throw new HttpException(500, string.Format("The {0} account has been disabled.", authTicket.Name));
}
if (user.IsAdmin)
roles = new string[] { "admin" };
//.........这里部分代码省略.........