Created
January 12, 2018 15:14
-
-
Save hbulens/3f071d841216759907caaf76ad47dda7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using log4net.Core; | |
using log4net.Layout.Pattern; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Web; | |
public class HttpContextUserPatternConverter : PatternLayoutConverter | |
{ | |
protected override void Convert(TextWriter writer, LoggingEvent loggingEvent) | |
{ | |
string name = ""; | |
HttpContext context = HttpContext.Current; | |
if (context != null && context.User != null && context.User.Identity.IsAuthenticated) | |
{ | |
name = context.User.Identity.Name; | |
} | |
writer.Write(name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment