Blog

  • Retrieve application log files

    Log files are a great resource for a Web developer, but only if you know how to find and use the logged information. Here, you look at the methods you can use to retrieve logged information for offline analysis.

    Log file storage locations

    The Azure infrastructure used to run Azure Web Apps in Windows isn’t the same as for Linux apps, and log files aren’t stored in the same locations.

    Windows app log files

    For Windows apps, file system log files are stored in a virtual drive that is associated with your Web App. This drive is addressable as D:\Home, and includes a LogFiles folder; within this folder are one or more subfolders:

    • Application – Contains application-generated messages, if File System application logging is enabled.
    • DetailedErrors – Contains detailed Web server error logs, if Detailed error messages are enabled.
    • http – Contains IIS-level logs, if Web server logging is enabled.
    • W3SVC<number> – Contains details of all failed http requests, if Failed request tracing is enabled.

    Where storage to a Blob container is enabled, logs are stored in year, month, date, and hour folders, for example:Copy

    2019
      01
       10
        08 - log entries for the period 08:00:00 to 08:59:59 on January 10th 2019
        09 - log entries for the period 09:00:00 to 09:59:59 on January 10th 2019
    

    Within the hour folder, there are one or more CSV files containing messages saved within that 60-minute period.

    Linux app log files

    For Linux Web Apps, the Azure tools currently support fewer logging options than for Windows apps. Redirections to STDERR and STDOUT are managed through the underlying Docker container that runs the app, and these messages are stored in Docker log files. To see messages logged by underlying processes, such as Apache, you need to open an SSH connection to the Docker container.

    Methods for retrieving log files

    How you retrieve log files depends on the type of log file, and on your preferred environment. For file system logs, you can use the Azure CLI or the Kudu console. Kudu is the engine behind many features in Azure App Service related to source control based deployment.

    php and mysql training courses malaysia
  • View live application logging with the log streaming service

    In this unit, you look at how to view a live app log stream, and how live log streams can help during Web app development.

    What is live log streaming?

    Live log streaming is an easy and efficient way to view live logs for troubleshooting purposes. Live log streaming provides a quick view of all the messages sent to the app logs in the file system, without having to go through the process of locating and opening the logs. To use live logging, you connect to the live log service from the command line, and you can then see text being written to the app’s logs in real time.

    What logs can be streamed?

    The log streaming service adds a redirect from the file system logs, so that you see the same information that is saved to the log files. So, if you enable verbose logging for ASP.NET Windows apps, for example, the live log stream shows all your logged messages.

    Screenshot of Azure portal live log stream pane showing output from the asp logs container.

    Typical scenarios for using live logging

    Live logging is a useful tool for initial debugging. Real time log messages give you immediate feedback for code or server issues. You can then make a change, redeploy your app, and instantly see the results.

    The live log stream connects to a single app instance, so it’s not useful if you have a multi-instance app. Live logging is also of limited use as you scale up your apps. In these scenarios, it’s better to ensure that messages are saved to log files that can be opened and studied offline.

    red hat openstack training courses malaysia

  • ASP.NET

    ASP.NET apps only run on Windows app services. To log information to the app diagnostics log, use the System.Diagnostics.Trace class. There are four trace levels you can use, that correlate with the errorwarninginformation, and verbose logging levels shown in the Azure portal:

    • Trace.TraceError(“Message”); // Writes an error message
    • Trace.TraceWarning(“Message”); // Writes a warning message
    • Trace.TraceInformation(“Message”); // Writes an information message
    • Trace.WriteLine(“Message”); // Writes a verbose message

    ASP.NET Core apps

    ASP.NET Core apps can run on either Windows or Linux. To log information to Azure app logs, use the logger factory class, and then use one of six-log levels:

    • logger.LogCritical(“Message”); // Writes a critical message at log level 5
    • logger.LogError(“Message”); // Writes an error message at log level 4
    • logger.LogWarning(“Message”); // Writes a warning message at log level 3
    • logger.LogInformation(“Message”); // Writes an information message at log level 2
    • logger.LogDebug(“Message”); // Writes a debug message at log level 1
    • logger.LogTrace(“Message”); // Writes a detailed trace message at log level 0

    For ASP.NET Core apps on Windows, these messages relate to the filters in the Azure portal in this way:

    • Levels 4 and 5 are error messages.
    • Level 3 is a warning message.
    • Level 2 is an information message.
    • Levels 0 and 1 are verbose messages.

    For ASP.NET Core apps on Linux, only error messages (levels 4 and 5) are logged.

    Node.js apps

    For script-based Web apps, such as Node.js apps on Windows or Linux, app logging is enabled using the console() method:

    • console.error(“Message”); // Writes a message to STDERR.
    • console.log(“Message”); // Writes a message to STDOUT.

    Both types of message are written to the Azure app service error level logs.

    microsoft system center certification training courses malaysia
  • Enable and configure App Service application logging

    In this unit, we look at how app logging can help with your Web apps, and show you how to enable app logs.

    What are app logs?

    Azure provides built-in diagnostics with app logging. App logs are the output of runtime trace statements in app code. For example, you might want to check some logic in your code by adding a trace to show when a particular function is being processed. Or, you might only want to see a logged message when a particular level of error occurs. App logging is primarily for apps in preproduction and for troublesome issues, because excessive logs can carry a performance hit and quickly consume storage. For this reason, logging to the file system is automatically disabled after 12 hours.

    App logging has scale limitations, primarily because files are being used to save the logged output. If you have multiple instances of an app, and the same storage is shared across all instances, messages from different instances might be interleaved, making troubleshooting difficult. If each instance has its own log file, then there are multiple logs, again making it difficult to troubleshoot instance-specific issues.

    The types of logging available through the Azure App Service depends on the code framework of the app, and on whether the app is running on a Windows or Linux app host.

    visual studio net training courses malaysia
  • Scale up a web app

    Scaling out enables you to run more instances of a web app. The pricing tier determines resources available to each instance used by the App Service plan that hosts the web service. Each pricing tier specifies the computing power provided, together with the memory and maximum number of instances that can be created.

    If you initially deploy a web app using a relatively cheap pricing tier, you might find the resources are sufficient to start with. But the resources might become too limited if demand for your web service grows, or if you add features that require more power. In this case, you can scale up to a more powerful pricing tier.

    In the hotel reservation system, you notice a steady increase in the number of visitors, beyond the variations caused by special offers or events. Your company is adding more features to the web app that require more resources. You’re nearing the scale-out limits of your current App Service plan pricing tier, so you need to scale up to a tier that provides more instances and more powerful hardware.

    In this unit, you learn how to scale up the web app to meet the increasing resource requirements.

    ai and machine learning training courses malaysia
  • Scale a web app manually

    By manually scaling out and back in again, you can respond to expected increases and decreases in traffic. Scaling out has the extra benefit of increasing availability because of the increased number of instances of the web app. A failure of one instance doesn’t make the web app unavailable.

    In the hotel reservation system, you can scale out before an anticipated seasonal influx. You can scale back in when the season is over and the number of booking requests is reduced.

    In this unit, you learn how to manually scale out a web app and how to scale it back in.

    App Service plans and scalability

    A web app that runs in Azure typically uses Azure App Service to provide the hosting environment. App Service can arrange for multiple instances of the web app to run. It load balances incoming requests across these instances. Each instance runs on a virtual machine.

    An App Service plan defines the resources available to each instance. The App Service plan specifies the operating system (Windows or Linux), the hardware (memory, CPU processing capacity, disk storage, and so on), and the availability of services like automatic backup and restore.

    Azure provides a series of well-defined App Service plan tiers. This list summarizes each of these tiers, in increasing order of capacity and cost:

    • The Free tier provides 1 GB of disk space and support for up to 10 apps, but only a single shared instance and no SLA for availability. Each app has a compute quota of 60 minutes per day. The Free service plan is suitable for app development and testing rather than production deployments.
    • The Shared tier provides support for more apps (up to 100) also running on a single shared instance. Apps have a compute quota of 240 minutes per day. There’s no availability SLA.
    • The Basic tier supports an unlimited number of apps and provides more disk space. Apps can be scaled out to three dedicated instances. This tier provides an SLA of 99.95% availability. There are three levels in this tier that offer varying amounts of computing power, memory, and disk storage.
    • The Standard tier also supports an unlimited number of apps. This tier can scale to 10 dedicated instances and has an availability SLA of 99.95%. Like the Basic tier, this tier has three levels that offer an increasingly powerful set of computing, memory, and disk options.
    • The Premium tier gives you up to 20 dedicated instances, an availability SLA of 99.95%, and multiple levels of hardware.
    • The Isolated tier runs in a dedicated Azure virtual network, which gives you a network and computes isolation. This tier can scale out to 100 instances and has an availability SLA of 99.95%.
    lean six sigma certification training courses malaysia

  • Complete the challenge

    Code challenges throughout these modules will reinforce what you’ve learned and help you gain some confidence before continuing on.

    Challenge: Write code in the .NET Editor to display two messages

    1. Select all of the code in the .NET Editor, and press Delete or Backspace to delete it.
    2. Write code that produces the following output:OutputCopyThis is the first line. This is the second line. In the previous unit, you learned how to display a message in just one line of code, and you learned how to display a message using multiple lines of code. Use both techniques for this challenge. It doesn’t matter which technique you apply to which line, and it doesn’t matter how many ways you split one of the messages into multiple lines of code. That’s your choice.
    agile and scrum training courses malaysia 2
  • What is syntax?

    The rules for writing C# code is called syntax. Just like human languages have rules regarding punctuation and sentence structure, computer programming languages also have rules. Those rules define the keywords and operators of C# and how they are put together to form programs.

    When you wrote code into the .NET Editor, you may have noticed subtle changes to the color of different words and symbols. Syntax highlighting is a helpful feature that you’ll begin to use to easily spot mistakes in your code that don’t conform to the syntax rules of C#.

    How did your code work?

    Let’s focus on the following line of code you wrote:

    C#Copy

    Console.WriteLine("Hello World!");
    

    When you ran your code, you saw that the message Hello World! was printed to the output console. When the phrase is surrounded by double-quotation marks in your C# code, it’s called a literal string. In other words, you literally wanted the characters Hello, and so on, sent to the output.

    The Console part is called a class. Classes “own” methods; or you could say that methods live inside of a class. To visit the method, you must know which class it’s in. For now, think of a class as a way to represent an object. In this case, all of the methods that operate on your output console are defined inside of the Console class.

    There’s also a dot (or period) that separates the class name Console and the method name WriteLine(). The period is the member access operator. In other words, the dot is how you “navigate” from the class to one of its methods.

    The WriteLine() part is called a method. You can always spot a method because it has a set of parentheses after it. Each method has one job. The WriteLine() method’s job is to write a line of data to the output console. The data that’s printed is sent in between the opening and closing parenthesis as an input parameter. Some methods need input parameters, while others don’t. But if you want to invoke a method, you must always use the parentheses after the method’s name. The parentheses are known as the method invocation operator.

    Finally, the semicolon is the end of statement operator. A statement is a complete instruction in C#. The semicolon tells the compiler that you’ve finished entering the command.

    adroid training courses malaysia
  • Learn how it works

    To understand how your code works, you need to step back and think about what a programming language is. Consider how your code communicates commands to the computer.

    What is a programming language?

    Programming languages like C# let you write instructions that you want the computer to carry out. Each programming language has its own syntax, but after learning your first programming language and attempting to learn another one, you’ll quickly realize that they all share many similar concepts. A programming language’s job is to allow a human to express their intent in a human-readable and understandable way. The instructions you write in a programming language are called “source code” or just “code”. Software developers write code.

    At this point, a developer can update and change the code, but the computer can’t understand the code. The code first must be compiled into a format that the computer can understand.

    What is compilation?

    A special program called a compiler converts your source code into a different format that the computer’s central processing unit (CPU) can execute. When you used the green Run button in the previous unit, the code you wrote was first compiled, then executed.

    Why does code need to be compiled? Although most programming languages seem cryptic at first, they can be more easily understood by humans than the computer’s preferred language. The CPU understands instructions that are expressed by turning thousands or millions of tiny switches either on or off. Compilers bridge these two worlds by translating your human-readable instructions into a computer-understandable set of instructions.

    agile and scrum training courses malaysia
  • The ASP.NET Core project templates

    Starting a new project, including setting up the initial structure and configurations, can be a daunting task. Fortunately, ASP.NET Core provides various project templates that simplify this process. The project templates offer a standardized and efficient way to kickstart your development. This unit explores the different ASP.NET Core project templates available and how to use them to create new projects.

    ai artificial intelligence training courses malaysia