当前位置: 首页>>代码示例>>C#>>正文


C# Layouts.SimpleLayout类代码示例

本文整理汇总了C#中NLog.Layouts.SimpleLayout的典型用法代码示例。如果您正苦于以下问题:C# SimpleLayout类的具体用法?C# SimpleLayout怎么用?C# SimpleLayout使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SimpleLayout类属于NLog.Layouts命名空间,在下文中一共展示了SimpleLayout类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SimpleLayoutCachingTest

 public void SimpleLayoutCachingTest()
 {
     var l = new SimpleLayout("xx${level}yy");
     var ev = LogEventInfo.CreateNullEvent();
     string output1 = l.Render(ev);
     string output2 = l.Render(ev);
     Assert.AreSame(output1, output2);
 }
开发者ID:rameshr,项目名称:NLog,代码行数:8,代码来源:SimpleLayoutOutputTests.cs

示例2: SimpleLayoutToStringTest

        public void SimpleLayoutToStringTest()
        {
            var l = new SimpleLayout("xx${level}yy");
            Assert.AreEqual("'xx${level}yy'", l.ToString());

            var l2 = new SimpleLayout(new LayoutRenderer[0], "someFakeText", ConfigurationItemFactory.Default);
            Assert.AreEqual("'someFakeText'", l2.ToString());
        }
开发者ID:rameshr,项目名称:NLog,代码行数:8,代码来源:SimpleLayoutOutputTests.cs

示例3: LayoutRendererThrows

 public void LayoutRendererThrows()
 {
     ConfigurationItemFactory configurationItemFactory = new ConfigurationItemFactory();
     configurationItemFactory.LayoutRenderers.RegisterDefinition("throwsException", typeof(ThrowsExceptionRenderer));
     
     SimpleLayout l = new SimpleLayout("xx${throwsException}yy", configurationItemFactory);
     string output = l.Render(LogEventInfo.CreateNullEvent());
     Assert.AreEqual("xxyy", output);
 }
开发者ID:rameshr,项目名称:NLog,代码行数:9,代码来源:SimpleLayoutOutputTests.cs

示例4: Append

        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
        {
            if (!_isCached)
            {
                _cachedValue = GetValue();
            }

            var layout = new SimpleLayout(_cachedValue);
            builder.Append(layout.Render(logEvent));
        }
开发者ID:takekazuomi,项目名称:NLog.Azure,代码行数:10,代码来源:LocalResourceLayoutRenderer.cs

示例5: TestConstructor

        public void TestConstructor()
        {
            const string name = "SomeName!";
            var layout = new SimpleLayout
                             {
                                 Text = "SomeText"
                             };

            var field = new MongoDBTargetField(name, layout);

            field.Name
                .Should().Be(name);
            field.Layout
                .Should().Be(layout);
        }
开发者ID:cihanozhan,项目名称:NLog.MongoDB,代码行数:15,代码来源:TestMongoTargetField.cs

示例6: ConfigureLogger

        public void ConfigureLogger()
        {
            var layout = new SimpleLayout("${date} [${threadid}] ${level} ${logger} ${ndc} - ${message}${newline}");

            var channelFactory = Substitute.For<ChannelFactory>();
            _channel = Substitute.For<IEventChannel>();
            channelFactory.Create("localhost", 8765, 1).Returns(_channel);
            _target = new BrowserConsoleTarget(channelFactory)
            {
                Host = "localhost",
                Port = 8765,
                Layout = layout,
                Buffer = 1,
                Name = "ConsoleTest"
            };
        }
开发者ID:momo3038,项目名称:BrowserLog,代码行数:16,代码来源:BrowserConsoleTargetTest.cs

示例7: ConfigureLogging

        static void ConfigureLogging()
        {
            if (LogManager.Configuration != null)
            {
                return;
            }

            var nlogConfig = new LoggingConfiguration();
            var simpleLayout = new SimpleLayout("${longdate}|${threadid}|${level}|${logger}|${message}${onexception:${newline}${exception:format=tostring}}");
            
            var fileTarget = new FileTarget
            {
                ArchiveEvery = FileArchivePeriod.Day,
                FileName = Path.Combine(Settings.LogPath, "logfile.txt"),
                ArchiveFileName = Path.Combine(Settings.LogPath, "log.{#}.txt"),
                ArchiveNumbering = ArchiveNumberingMode.Rolling,
                Layout = simpleLayout,
                MaxArchiveFiles = 14,
            };
            var consoleTarget = new ColoredConsoleTarget
            {
                Layout = simpleLayout,
                UseDefaultRowHighlightingRules = true,
            };

            nlogConfig.LoggingRules.Add(new LoggingRule("Raven.*", LogLevel.Warn, fileTarget));
            nlogConfig.LoggingRules.Add(new LoggingRule("Raven.*", LogLevel.Warn, consoleTarget) { Final = true });
            nlogConfig.LoggingRules.Add(new LoggingRule("NServiceBus.Licensing.*", LogLevel.Error, fileTarget));
            nlogConfig.LoggingRules.Add(new LoggingRule("NServiceBus.Licensing.*", LogLevel.Error, consoleTarget) { Final = true });

            nlogConfig.LoggingRules.Add(new LoggingRule("*", LogLevel.Warn, fileTarget));
            nlogConfig.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, consoleTarget)); 
            
            nlogConfig.AddTarget("debugger", fileTarget);
            nlogConfig.AddTarget("console", consoleTarget);
            NLogConfigurator.Configure(new object[] { fileTarget, consoleTarget }, "Info");
            LogManager.Configuration = nlogConfig;
        }
开发者ID:dmitriylyner,项目名称:ServiceControl,代码行数:38,代码来源:Bootstrapper.cs

示例8: ParseLayoutRenderer

        private static LayoutRenderer ParseLayoutRenderer(ConfigurationItemFactory configurationItemFactory, SimpleStringReader sr)
        {
            int ch = sr.Read();
            Debug.Assert(ch == '{', "'{' expected in layout specification");

            string name = ParseLayoutRendererName(sr);
            LayoutRenderer lr = configurationItemFactory.LayoutRenderers.CreateInstance(name);

            var wrappers = new Dictionary<Type, LayoutRenderer>();
            var orderedWrappers = new List<LayoutRenderer>();

            ch = sr.Read();
            while (ch != -1 && ch != '}')
            {
                string parameterName = ParseParameterName(sr).Trim();
                if (sr.Peek() == '=')
                {
                    sr.Read(); // skip the '='
                    PropertyInfo pi;
                    LayoutRenderer parameterTarget = lr;

                    if (!PropertyHelper.TryGetPropertyInfo(lr, parameterName, out pi))
                    {
                        Type wrapperType;

                        if (configurationItemFactory.AmbientProperties.TryGetDefinition(parameterName, out wrapperType))
                        {
                            LayoutRenderer wrapperRenderer;

                            if (!wrappers.TryGetValue(wrapperType, out wrapperRenderer))
                            {
                                wrapperRenderer = configurationItemFactory.AmbientProperties.CreateInstance(parameterName);
                                wrappers[wrapperType] = wrapperRenderer;
                                orderedWrappers.Add(wrapperRenderer);
                            }

                            if (!PropertyHelper.TryGetPropertyInfo(wrapperRenderer, parameterName, out pi))
                            {
                                pi = null;
                            }
                            else
                            {
                                parameterTarget = wrapperRenderer;
                            }
                        }
                    }

                    if (pi == null)
                    {
                        ParseParameterValue(sr);
                    }
                    else
                    {
                        if (typeof(Layout).IsAssignableFrom(pi.PropertyType))
                        {
                            var nestedLayout = new SimpleLayout();
                            string txt;
                            LayoutRenderer[] renderers = CompileLayout(configurationItemFactory, sr, true, out txt);

                            nestedLayout.SetRenderers(renderers, txt);
                            pi.SetValue(parameterTarget, nestedLayout, null);
                        }
                        else if (typeof(ConditionExpression).IsAssignableFrom(pi.PropertyType))
                        {
                            var conditionExpression = ConditionParser.ParseExpression(sr, configurationItemFactory);
                            pi.SetValue(parameterTarget, conditionExpression, null);
                        }
                        else
                        {
                            string value = ParseParameterValue(sr);
                            PropertyHelper.SetPropertyFromString(parameterTarget, parameterName, value, configurationItemFactory);
                        }
                    }
                }
                else
                {
                    // what we've just read is not a parameterName, but a value
                    // assign it to a default property (denoted by empty string)
                    PropertyInfo pi;

                    if (PropertyHelper.TryGetPropertyInfo(lr, string.Empty, out pi))
                    {
                        if (typeof(SimpleLayout) == pi.PropertyType)
                        {
                            pi.SetValue(lr, new SimpleLayout(parameterName), null);
                        }
                        else
                        {
                            string value = parameterName;
                            PropertyHelper.SetPropertyFromString(lr, pi.Name, value, configurationItemFactory);
                        }
                    }
                    else
                    {
                        InternalLogger.Warn("{0} has no default property", lr.GetType().FullName);
                    }
                }

                ch = sr.Read();
            }
//.........这里部分代码省略.........
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:101,代码来源:LayoutParser.cs

示例9: DetectFilePathKind

        /// <summary>
        /// Is this (templated/invalid) path an absolute, relative or unknown?
        /// </summary>
        private static FilePathKind DetectFilePathKind(SimpleLayout pathLayout)
        {
            var isFixedText = pathLayout.IsFixedText;

            //nb: ${basedir} has already been rewritten in the SimpleLayout.compile
            var path = isFixedText ? pathLayout.FixedText : pathLayout.Text;

            if (path != null)
            {
                path = path.TrimStart();

                int length = path.Length;
                if (length >= 1)
                {
                    var firstChar = path[0];
                    if (firstChar == Path.DirectorySeparatorChar || firstChar == Path.AltDirectorySeparatorChar)
                        return FilePathKind.Absolute;
                    if (firstChar == '.') //. and ..
                    {
                        return FilePathKind.Relative;
                    }


                    if (length >= 2)
                    {
                        var secondChar = path[1];
                        //on unix VolumeSeparatorChar == DirectorySeparatorChar
                        if (Path.VolumeSeparatorChar != Path.DirectorySeparatorChar && secondChar == Path.VolumeSeparatorChar)
                            return FilePathKind.Absolute;

                    }
                    if (!isFixedText && path.StartsWith("${", StringComparison.OrdinalIgnoreCase))
                    {
                        //if first part is a layout, then unknown
                        return FilePathKind.Unknown;
                    }


                    //not a layout renderer, but text
                    return FilePathKind.Relative;
                }
            }
            return FilePathKind.Unknown;
        }
开发者ID:rosj91,项目名称:NLog,代码行数:47,代码来源:FilePathLayout.cs

示例10: TryGetLayout

        /// <summary>
        /// Try get the 
        /// </summary>
        /// <param name="layout"></param>
        /// <returns></returns>
        private bool TryGetLayout(out SimpleLayout layout)
        {
            if (this.Name != null)
            {
                //don't use LogManager (locking, recursion)
                var loggingConfiguration = LoggingConfiguration; //?? LogManager.Configuration;
                var vars = loggingConfiguration != null ? loggingConfiguration.Variables : null;
                if (vars != null && vars.TryGetValue(Name, out layout))
                {
                    return true;
                }

            }
            layout = null;
            return false;
        }
开发者ID:CharlieBP,项目名称:NLog,代码行数:21,代码来源:VariableLayoutRenderer.cs

示例11: SdId

 public SdId(SimpleLayout sdIdConfig, EnforcementConfig enforcementConfig)
 {
     layout = sdIdConfig;
     sdIdPolicySet = new SdIdPolicySet(enforcementConfig);
 }
开发者ID:graffen,项目名称:NLog.Targets.Syslog,代码行数:5,代码来源:SdId.cs

示例12: WrapperOverAgnostic

 public void WrapperOverAgnostic()
 {
     Layout l = new SimpleLayout("${rot13:${message}}");
     l.Initialize(null);
     Assert.True(l.IsThreadAgnostic);
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:6,代码来源:ThreadAgnosticTests.cs

示例13: NLogConfigurationException

        void ISupportsLazyParameters.CreateParameters(LoggingConfiguration cfg)
        {
            bool foundProvider = false;

            if (!string.IsNullOrEmpty(ConnectionStringName))
            {
                // read connection string and provider factory from the configuration file
                var cs = ConnectionStringsSettings[ConnectionStringName];
                if (cs == null)
                {
                    throw new NLogConfigurationException("Connection string '" + ConnectionStringName + "' is not declared in <connectionStrings /> section.");
                }

                ConnectionString = new SimpleLayout(SimpleLayout.Escape(cs.ConnectionString), cfg);
                ProviderFactory = DbProviderFactories.GetFactory(cs.ProviderName);
                foundProvider = true;
            }

            if (!foundProvider)
            {
                foreach(DataRow row in DbProviderFactories.GetFactoryClasses().Rows)
                {
                    if ((string)row["InvariantName"] == DBProvider)
                    {
                        ProviderFactory = DbProviderFactories.GetFactory(DBProvider);
                        foundProvider = true;
                    }
                }
            }

            if (!foundProvider)
            {
                switch (DBProvider.ToUpper(CultureInfo.InvariantCulture))
                {
                    case "SQLSERVER":
                    case "MSSQL":
                    case "MICROSOFT":
                    case "MSDE":
                        ConnectionType = systemDataAssembly.GetType("System.Data.SqlClient.SqlConnection", true);
                        break;

                    case "OLEDB":
                        ConnectionType = systemDataAssembly.GetType("System.Data.OleDb.OleDbConnection", true);
                        break;

                    case "ODBC":
                        ConnectionType = systemDataAssembly.GetType("System.Data.Odbc.OdbcConnection", true);
                        break;

                    default:
                        ConnectionType = Type.GetType(DBProvider, true);
                        break;
                }
            }
        }
开发者ID:ExM,项目名称:NLog,代码行数:55,代码来源:DatabaseTarget.cs

示例14: CustomNotAgnosticTests

        public void CustomNotAgnosticTests()
        {
            var cif = new ConfigurationItemFactory();
            cif.RegisterType(typeof(CustomRendererNonAgnostic), string.Empty);
            var cfg = new LoggingConfiguration(cif);
            Layout l = new SimpleLayout("${customNotAgnostic}", cfg);

            l.Initialize(cfg);
            Assert.IsFalse(l.IsThreadAgnostic);
        }
开发者ID:ExM,项目名称:NLog,代码行数:10,代码来源:ThreadAgnosticTests.cs

示例15: Start


//.........这里部分代码省略.........
                    }
                    else if ( lowerCaseArgument.Equals( "autosave" ) )
                    {
                        if ( !int.TryParse( argValue, out extenderArgs.Autosave ) )
                            BaseLog.Warn( "Autosave parameter was not a valid integer." );
                    }
                    else if ( lowerCaseArgument.Equals( "path" ) )
                    {
                        if ( argValue[ argValue.Length - 1 ] == '"' )
                            argValue = argValue.Substring( 1, argValue.Length - 2 );
                        extenderArgs.InstancePath = argValue;
                    }
                    else if ( lowerCaseArgument.Equals( "instancepath" ) )
                    {
                        if ( argValue[ argValue.Length - 1 ] == '"' )
                            argValue = argValue.Substring( 1, argValue.Length - 2 );
                        extenderArgs.InstancePath = argValue;
                    }
                    else if (lowerCaseArgument.Equals("title") )
                    {
                        if (argValue[argValue.Length - 1] == '"')
                            argValue = argValue.Substring(1, argValue.Length - 2);
                        extenderArgs.ConsoleTitle = argValue;
                    }
                    else if ( lowerCaseArgument == "logpath" )
                    {
                        if ( argValue[ argValue.Length - 1 ] == '"' )
                            argValue = argValue.Substring( 1, argValue.Length - 2 );

                        //This argument always prevails.
                        FileTarget baseLogTarget = LogManager.Configuration.FindTargetByName( "BaseLog" ) as FileTarget;
                        if ( baseLogTarget != null )
                        {
                            Layout l = new SimpleLayout( Path.Combine( argValue, "SEServerExtenderLog-${shortdate}.log" ) );
                            baseLogTarget.FileName = l.Render( new LogEventInfo { TimeStamp = DateTime.Now } );
                            ApplicationLog.BaseLog = BaseLog;
                        }
                        FileTarget chatLogTarget = LogManager.Configuration.FindTargetByName( "ChatLog" ) as FileTarget;
                        if ( chatLogTarget != null )
                        {
                            Layout l = new SimpleLayout( Path.Combine( argValue, "ChatLog-${shortdate}.log" ) );
                            chatLogTarget.FileName = l.Render( new LogEventInfo { TimeStamp = DateTime.Now } );
                            ApplicationLog.ChatLog = ChatLog;
                        }
                        FileTarget pluginLogTarget = LogManager.Configuration.FindTargetByName( "PluginLog" ) as FileTarget;
                        if ( pluginLogTarget != null )
                        {
                            Layout l = new SimpleLayout( Path.Combine( argValue, "PluginLog-${shortdate}.log" ) );
                            pluginLogTarget.FileName = l.Render( new LogEventInfo { TimeStamp = DateTime.Now } );
                            logPathSet = true;
                            ApplicationLog.PluginLog = PluginLog;
                        }

                    }
                }
                else
                {
                    string lowerCaseArgument = arg.ToLower( );
                    if ( lowerCaseArgument.Equals( "autostart" ) )
                    {
                        extenderArgs.AutoStart = true;
                    }
                    else if ( lowerCaseArgument.Equals( "nogui" ) )
                    {
                        extenderArgs.NoGui = true;
开发者ID:stansan,项目名称:SEServerExtender,代码行数:66,代码来源:Program.cs


注:本文中的NLog.Layouts.SimpleLayout类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。