/// <summary> /// Add the standard (in the opinion of this class) conversions. /// </summary> /// <remarks> /// <para> /// TODO: (Rant) I'm not entirely happy with this monster. /// I wish s_globalRulesRegistry and friends in <seealso cref="PatternLayout"/> /// would better lend themselves to code reuse. /// There could be a simple ConvertorCollection class exposing that functionality /// which I'd re-use to create the following matrix with the already declared convertors. /// </para> /// </remarks> /// <param name="calls">calls to add to</param> /// <returns>calls added</returns> public static IEnumerable <RawCallLayout> MakeOverrideCalls(IEnumerable <RawCallLayout> calls) { // these calls should grab the same info as log4net would, but try to get it in raw format so that // value is serialized later by a specific serializer. RawCallLayout.AddCalls(ref calls, e => e.TimeStamp.ToUniversalTime().ToString("o"), "utcdate", "utcDate", "UtcDate"); RawCallLayout.AddCalls(ref calls, e => e.TimeStamp.ToString("o"), "date", "d"); RawCallLayout.AddCalls(ref calls, e => e.Level.DisplayName, "level", "p"); RawCallLayout.AddCalls(ref calls, e => e.LoggerName, "logger", "c"); RawCallLayout.AddCalls(ref calls, e => e.ThreadName, "thread", "t"); RawCallLayout.AddCalls(ref calls, e => e.RenderedMessage, "message", "raw_event" /*custom*/, "m"); RawCallLayout.AddCalls(ref calls, e => e.MessageObject, "messageobject" /*custom*/, "mo" /*custom*/); RawCallLayout.AddCalls(ref calls, e => e.ExceptionObject == null ? null : e.GetExceptionString(), "exception", "e" /*custom*/); RawCallLayout.AddCalls(ref calls, e => e.ExceptionObject, "exceptionobject" /*custom*/, "eo" /*custom*/); RawCallLayout.AddCalls(ref calls, e => e.Identity, "identity", "u"); RawCallLayout.AddCalls(ref calls, e => e.UserName, "username", "w"); RawCallLayout.AddCalls(ref calls, e => e.GetProperties(), "property", "properties", "mdc", "P", "X"); RawCallLayout.AddCalls(ref calls, e => e.LookupProperty("NDC"), "ndc", "x"); RawCallLayout.AddCalls(ref calls, e => e.Domain, "appdomain", "a"); if (s_webappname == null) { RawCallLayout.AddCalls(ref calls, e => Environment.CommandLine, "apppath" /*custom*/); RawCallLayout.AddCalls(ref calls, e => e.Domain, "appname" /*custom*/); } else { RawCallLayout.AddCalls(ref calls, e => e.Domain, "apppath" /*custom*/); RawCallLayout.AddCalls(ref calls, e => s_webappname, "appname" /*custom*/); } RawCallLayout.AddCalls(ref calls, e => e.LocationInformation.ClassName, "type", "class", "C"); RawCallLayout.AddCalls(ref calls, e => e.LocationInformation.FileName, "file", "F"); RawCallLayout.AddCalls(ref calls, e => e.LocationInformation.FullInfo, "location", "l"); RawCallLayout.AddCalls(ref calls, e => e.LocationInformation.LineNumber, "line", "L"); RawCallLayout.AddCalls(ref calls, e => e.LocationInformation.MethodName, "method", "M"); #if !LOG4NET_1_2_10_COMPATIBLE RawCallLayout.AddCalls(ref calls, e => e.LocationInformation.StackFrames, "stacktrace"); RawCallLayout.AddCalls(ref calls, e => e.LocationInformation.StackFrames, "stacktracedetail"); #endif RawCallLayout.AddCalls(ref calls, e => (e.TimeStamp - LoggingEvent.StartTime).TotalMilliseconds, "timestamp", "r"); RawCallLayout.AddCalls(ref calls, e => Environment.NewLine, "newline", "n"); RawCallLayout.AddCalls(ref calls, e => s_processId, "processid" /*custom*/, "pid" /*custom*/); RawCallLayout.AddCalls(ref calls, e => Environment.MachineName, "hostname" /*custom*/, "h" /*custom*/); RawCallLayout.AddCalls(ref calls, e => Environment.CommandLine, "commandline" /*custom*/); RawCallLayout.AddCalls(ref calls, e => Environment.UserName, "user" /*custom*/); RawCallLayout.AddCalls(ref calls, e => Environment.UserDomainName, "domain" /*custom*/); RawCallLayout.AddCalls(ref calls, e => Environment.WorkingSet, "memory" /*custom*/); RawCallLayout.AddCalls(ref calls, e => Environment.WorkingSet, "memory" /*custom*/); return(calls); }
/// <summary> /// Find an appropriate <see cref="IRawLayout"/> for the specified conversion name using own defaults or <see cref="ConverterInfo"/>s provided. /// </summary> /// <param name="name">name of conversion</param> /// <param name="converters">converters we can use to work out the conversions</param> /// <returns>call found</returns> public static IRawLayout FindLayout(string name, ConverterInfo[] converters) { return(FindLayout(name, RawCallLayout.GetCalls(converters))); }
/// <summary> /// Get the standard calls enhanced by converters /// </summary> /// <param name="converters"></param> /// <returns>enhanced standard calls</returns> public static IEnumerable <RawCallLayout> GetCalls(ConverterInfo[] converters) { return(RawCallLayout.CombineCalls(OverrideCalls, converters)); }