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


C# LogWriter.WriteLine方法代码示例

本文整理汇总了C#中LogWriter.WriteLine方法的典型用法代码示例。如果您正苦于以下问题:C# LogWriter.WriteLine方法的具体用法?C# LogWriter.WriteLine怎么用?C# LogWriter.WriteLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LogWriter的用法示例。


在下文中一共展示了LogWriter.WriteLine方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: XtractModuleCommands

        /// <summary>
        /// Extracts the module information from the provided xml document
        /// </summary>
        /// <param name="module">The module to load the commands in</param>
        /// <param name="doc">The document from where the commands will be loaded</param>
        /// <param name="log">The log writer</param>
        /// <returns>Returns a list of prototypes which contains the command information.</returns>
        private static Prototype[] XtractModuleCommands(ModuleClient module, XmlDocument doc, LogWriter log)
        {
            XmlNodeList commands;
            List<Prototype> protoList;
            Prototype proto;
            string cmdName;
            bool cmdParams;
            bool cmdAnswer;
            bool cmdPriority;
            int cmdTimeOut;

            // Get the list of commands. If none, return
            log.WriteLine(2, "\tLoading module commands...");
            if (doc.GetElementsByTagName("commands").Count < 1)
            {
                log.WriteLine(3, "\tNo commands to load");
                return null;
            }

            commands = doc.GetElementsByTagName("commands")[0].ChildNodes;
            protoList = new List<Prototype>(commands.Count);

            #region Module command extraction

            for (int j = 0; j < commands.Count; ++j)
            {
                // Verify that the node is a command
                cmdTimeOut = 0;
                if ((commands[j].Name == "command") &&
                (commands[j].Attributes.Count >= 3) &&
                (commands[j].Attributes["name"].Value.Length > 1) &&
                Boolean.TryParse(commands[j].Attributes["answer"].Value, out cmdAnswer) &&
                (
                    (cmdAnswer && Int32.TryParse(commands[j].Attributes["timeout"].Value, out cmdTimeOut) && (cmdTimeOut >= 0)) || !cmdAnswer
                ))
                {
                    // Read command name
                    cmdName = commands[j].Attributes["name"].Value;
                    log.WriteLine(2, "\t\tAdded command " + cmdName);
                    // Check if command require parameters
                    if ((commands[j].Attributes["parameters"] == null) || !Boolean.TryParse(commands[j].Attributes["parameters"].Value, out cmdParams))
                        cmdParams = true;
                    // Check if command has preiority
                    if ((commands[j].Attributes["priority"] == null) || !Boolean.TryParse(commands[j].Attributes["priority"].Value, out cmdPriority))
                        cmdPriority = false;
                    // Create the prototype
                    proto = new Prototype(cmdName, cmdParams, cmdAnswer, cmdTimeOut, cmdPriority);
                    // Add the prototype to the module
                    module.Prototypes.Add(proto);
                    protoList.Add(proto);
                }
                else log.WriteLine(4, "\t\tInvalid Command ");
            }
            #endregion
            // If there are no commands supported by the module, skip it.
            if (protoList.Count < 1)
                log.WriteLine(3, "\tAll commands rejected.");

            return protoList.ToArray();
        }
开发者ID:BioRoboticsUNAM,项目名称:Blackboard,代码行数:67,代码来源:Blackboard.cs

示例2: Invoke

        public async Task Invoke(HttpContext context)
        {
            if (!IsImageRequest(context))
            {
                // move to the next request here?
                await _next.Invoke(context);
                return;
            }

            try
            {
                var sb = new StringBuilder();
                sb.AppendLine("=====================================================================================================");
                sb.AppendLine("Date/Time: " + DateTime.UtcNow.ToString("M/d/yyyy hh:mm tt"));

                int width = 0;
                int.TryParse(context.Request.Query["width"], out width);
                int height = 0;
                int.TryParse(context.Request.Query["height"], out height);

                var inputPath = _appEnvironment.ApplicationBasePath + "/wwwroot" + context.Request.Path;
                using (var inputStream = File.OpenRead(inputPath))
                {
                    sb.AppendLine("Input Path: " + inputPath);
                    sb.AppendLine("Querystring Dimensions: " + width.ToString() + "x" + height.ToString());

                    var sw = new Stopwatch();
                    sw.Start();
                    var image = new Image(inputStream);
                    if (image.Width > image.Height && width != 0)
                        height = (125 * image.Height) / image.Width;
                    if (image.Height > image.Width && height != 0)
                        width = (125 * image.Width) / image.Height;
                    sw.Stop();

                    sb.AppendLine("Original Dimensions: " + image.Width.ToString() + "x" + image.Height.ToString());
                    sb.AppendLine("Output Dimensions: " + width.ToString() + "x" + height.ToString());
                    sb.AppendLine("Image Read Time in Seconds: " + sw.Elapsed.TotalSeconds.ToString());

                    // write directly to the body output stream
                    using (var outputStream = new MemoryStream())
                    {
                        sw.Restart();
                        image.Resize(width, height)
                            .Save(outputStream);
                        var bytes = outputStream.ToArray();
                        sw.Stop();
                        sb.AppendLine("Image Processing Time in Seconds: " + sw.Elapsed.TotalSeconds.ToString());

                        //context.Response.Body.Write(bytes, 0, bytes.Length);
                        await context.Response.Body.WriteAsync(bytes, 0, bytes.Length);
                    }

                    //// the following approach will write to disk then serve the image
                    ////var inputPath = _appEnvironment.ApplicationBasePath + "/wwwroot" + context.Request.Path;
                    //var outputPath = _appEnvironment.ApplicationBasePath + "/Uploads/" + Path.GetFileName(context.Request.Path);
                    //using (var outputStream = File.OpenWrite(outputPath))
                    //{
                    //    image.Resize(width, height)
                    //        .Save(outputStream);
                    //}
                    //var bytes = File.ReadAllBytes(outputPath);
                    //await context.Response.Body.WriteAsync(bytes, 0, bytes.Length);
                }

                //var logFilePath = _appEnvironment.ApplicationBasePath + "/Logs/ThumbnailLog-" + DateTime.UtcNow.ToString("yyyy-MM-dd-hh-mm-ss") + ".txt";
                var logFilePath = _appEnvironment.ApplicationBasePath + "/Logs/ThumbnailLog.txt";
                var logWriter = new LogWriter(logFilePath);
                logWriter.Write(sb.ToString());
            }
            catch (Exception ex)
            {
                var logFilePath = _appEnvironment.ApplicationBasePath + "/Logs/Exceptions.txt";
                var logWriter = new LogWriter(logFilePath);
                logWriter.WriteLine("=====================================================================================================");
                logWriter.WriteLine(ex.ToString());
            }

            //await _next.Invoke(context);
        }
开发者ID:Quintinon,项目名称:AspnetCoreFileManager,代码行数:80,代码来源:ThumbnailMiddleware.cs


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