Sitecore Loggings

Published date: 26/07/2025

Sitecore's logging system, primarily powered by log4net, is a fundamental aspect of maintaining and troubleshooting Sitecore solutions. It records events, errors, and other vital information, providing developers and administrators with insights into application behavior.

How Sitecore Logging Works

Sitecore uses the log4net framework, a popular open-source logging utility for .NET. This framework provides a flexible and extensible way to log messages to various output targets (known as "appenders"), such as files, databases, or even email.

When you use Sitecore's logging API (e.g., Sitecore.Diagnostics.Log.Info(), Sitecore.Diagnostics.Log.Error()), the messages are routed through log4net. The log4net configuration, typically defined in .config files within your Sitecore instance, dictates where these messages are written, what level of detail is included, and how log files are managed (e.g., rolling files by date or size).

Key Components of Sitecore Logging

  • Log Levels: These define the severity or importance of a log message. Sitecore, like log4net, typically supports levels such as:
    • FATAL: Critical errors that cause application failure.
    • ERROR: Errors that prevent specific functionalities from working correctly.
    • WARN: Unexpected behaviors or potential issues that don't necessarily halt operations.
    • INFO: General informational messages about application flow and state.
    • DEBUG: Detailed information useful for debugging.
    • TRACE: Extremely granular details showing step-by-step execution, often used for extended debugging sessions.

Logging frameworks allow you to configure a minimum log level. For example, if the logging level is set to "WARN," only messages with "WARN," "ERROR," and "FATAL" levels will be recorded.

  • Appenders: Appenders are responsible for writing log messages to a specific destination. Common appenders in Sitecore include:
    • SitecoreLogFileAppender (or RollingFileAppender): Writes logs to files, often with rolling policies (e.g., creating a new file daily or when a file reaches a certain size).
    • ADONetAppender: Writes logs to a database.
    • Custom Appenders: Developers can create their own appenders to integrate with specific logging services or systems.
  • Loggers: A logger is a named entity that acts as an entry point for logging messages. Each logger can be configured with a specific log level and can reference one or more appenders. Sitecore has default loggers for various functionalities (e.g., general system logs, crawling, publishing, search).
  • Configuration Files: Sitecore's logging is configured through XML files, often patched into the main web.config or specific include files within the App_Config/Include folder. These configurations define appenders, loggers, their levels, and file-specific settings like file paths and rolling policies.

Default Log Files and Locations

Sitecore typically stores its log files in the \App_Data\logs\ folder relative to your Sitecore website root. Some common default log files include:

  • yyyymmdd.txt: The main Sitecore log file, containing general system messages, errors, and informational events.
  • log.yyyymmdd.txt: Logs related to indexing and content crawling processes.
  • log.yyyymmdd.txt: Logs specific to search operations (e.g., Lucene queries).
  • log.yyyymmdd.txt: Contains information about publishing activities.
  • log.yyyymmdd.txt: For client-side (JavaScript) events, if configured.
  • log.yyyymmdd.txt: Log file for the Federated Experience Manager module.

Sitecore also provides a Log Viewer tool, accessible via /sitecore/admin/Logs.aspx, which allows administrators to view and download these log files directly from the browser.

Custom Logging

Developers often need to create custom log files for specific modules, integrations, or complex processes to isolate their logs from the main Sitecore logs. This helps in easier debugging and analysis. To set up custom logging:

  1. Define an Appender: Create a new appender configuration in an include file. This defines the destination (e.g., a specific file path) and formatting for your custom logs.
      
      <appender name="MyCustomLogFileAppender" type="log4net.Appender.SitecoreLogFileAppender, Sitecore.Logging">
        <file value="$(dataFolder)/logs/MyCustom.log.{date}.txt" />
        <appendToFile value="true" />
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%4t %d{ABSOLUTE} %-5p %m%n" />
        </layout>
    </appender>
    
      
      
  1. Define a Logger: Create a logger that references your custom appender and specifies the desired log level.
      
      	<logger name="MyProject.CustomLogger" additivity="false">
        <level value="INFO" />
        <appender-ref ref="MyCustomLogFileAppender" />
    </logger>
    
      
      
  1. Implement Logging in Code: Use Sitecore.Diagnostics.LoggerFactory.GetLogger("MyProject.CustomLogger") to get an instance of your custom logger and then call its methods (Info(), Error(), etc.) to write messages.
      
      	using Sitecore.Diagnostics;
    public static class MyLogger
    {
        private static readonly ILog Log = LoggerFactory.GetLogger("MyProject.CustomLogger");
    
        public static void LogInfo(string message)
        {
            Log.Info(message, typeof(MyLogger));
        }
    
        public static void LogError(string message, Exception ex)
        {
            Log.Error(message, ex, typeof(MyLogger));
        }
    }
    
      
      

 

Best Practices and Considerations

  • Avoid Over-logging: Too much logging can lead to performance degradation due to increased I/O operations and can make log analysis difficult. Log only essential information.
  • Appropriate Log Levels: Use log levels wisely. Debug and Trace logs should generally be disabled in production environments.
  • Mask Sensitive Information: Never log sensitive data (e.g., passwords, personally identifiable information) in plain text. Mask or redact such information before logging.
  • Complete Exceptions: Always log the complete exception details, including stack traces, not just the message.
  • Structured Logging: For advanced scenarios and easier analysis with log management tools, consider implementing structured logging (e.g., with Serilog). This involves logging data as key-value pairs, making it more machine-readable.
  • Log Archiving and Cleanup: Implement a strategy for archiving and cleaning up old log files to manage disk space. Sitecore has built-in cleanup agents that can be configured.
  • SIEM Integration: For large-scale deployments, integrate Sitecore logs with Security Information and Event Management (SIEM) tools for centralized log management, monitoring, and alerting.
  • Performance Impact: Be aware that excessive or poorly configured logging can impact performance. Sitecore versions 9.2 and later have improvements related to logging virtual users, addressing some performance concerns.

Ways to access Sitecore log files

  1. Through Browser:
    If you need to manage your Sitecore solution, you'll find various administration pages available. You can reach all these pages through the /sitecore/admin/default.aspx URL, but you'll need administrator privileges to access them. These admin pages are only available on Content Management (CM) and Standalone Sitecore roles.

    One helpful page is aspx, which lets you view Sitecore's log files. These logs are stored on your local system in the folder defined by the LogFolder setting within Sitecore. By default, this is set to $(dataFolder)/logs.
      
      <setting name="LogFolder" value="$(dataFolder)/logs" />
      
      
    To directly open the Logs page, just go to: https://<application hostname>/sitecore/admin/Logs.aspx
  2. Via folder explorer:

    Sitecore, by default, stores its log files in the /Data/logs This folder is typically located within the root directory of your Sitecore website installation. For example, if your Sitecore instance is installed in C:\inetpub\wwwroot\MySitecoreInstance, then the logs would be in C:\inetpub\wwwroot\MySitecoreInstance\Data\logs.

    The specific log folder location is determined by the LogFolder setting in your Sitecore configuration. By default, this setting is usually defined in your web.config or a related configuration file (often Sitecore.config in App_Config) as:

      
      <setting name="LogFolder" value="$(dataFolder)/logs" />
      
      


    The $(dataFolder) variable usually points to the /Data directory relative to your website root.

    How to Access Them:
    1. Navigate to your Sitecore instance's root directory on your server.
    2. Open the Data
    3. Open the logs folder within Data.
    4. You'll see all the Sitecore log files listed there, typically organized by date. You can open them with any plain text editor (like Notepad, Notepad++, or VS Code) to view their contents.


  3. Azure Deployments:
    1. Azure Application Insights:

      If your Sitecore deployment is on Azure, you can use Azure Application Insights to analyze your logs. You'll find Application Insights accessible directly through the Azure portal, where you can search for particular log entries, filter by event types such as exceptions or traces, and examine the details of your logs. Additionally, some users on Stack Exchange have noted that you might also be able to access logs through your web app's SCM site, for example, by navigating to https://your_azure_web_app_name.scm.azurewebsites.net/DebugConsole.
    2. Kudu Console (SCM Site): For Azure App Services, you can access a debug console (Kudu) via https://your_azure_web_app_name.scm.azurewebsites.net/DebugConsole to browse and download files, including logs.

Understanding the location and purpose of these log files is crucial for troubleshooting and monitoring your Sitecore solution.

Working with Sitecore logs offers a lot of power to understand and manage your solution. Here's a breakdown of what you can achieve:

Unlocking the Power of Sitecore Logs

  1. Keeping an Eye on Performance

Sitecore logs are incredibly useful for monitoring system performance. You can dig into the data to find out what's slowing things down, like bottlenecks causing slow page loads or too many database queries. They also help you track resource usage – think CPU, memory, and disk space – to spot processes that are hogging resources and need optimizing. Plus, by analyzing log data, you can even understand user behaviour, seeing what pages people visit, how they interact, and what content they consume.

  1. Pinpointing Errors and Issues

When things go wrong, logs are your best friend for diagnosing errors and issues. They let you trace activity, showing you the steps a user took or system events that led up to a problem, making it easier to find the root cause. You can even set up alerts or automated responses to specific error conditions, allowing you to react quickly to events. Essentially, examining log entries helps you understand the context of an error, figure out which components are failing, and troubleshoot the underlying problem.

  1. Boosting Security and Compliance

Logs are vital for ensuring security and compliance. They help you detect suspicious behaviour, like unusual login attempts or unauthorized access that could signal a security breach. You can also track security events such as failed logins, access violations, or even data breaches. By monitoring log data and generating audit reports, you can maintain compliance with regulations and internal security policies.

Proactive Strategies and Advanced Analysis

  1. Solving Problems Before They Start

For a more proactive approach, you can implement clear logging policies to ensure logs are collected, stored, and analyzed effectively. Consider automating log analysis with various tools and techniques to identify potential issues before they become major problems. You can also generate custom reports from your log data to get insights into system performance, security, and compliance.

  1. Diving Deeper with Advanced Analysis

To get the most out of your logs, think about integrating them with monitoring tools like Azure Application Insights or other third-party solutions. This gives you centralized log management and analysis. Utilizing log aggregation and correlation can help you connect different log events to get a more complete picture of system behaviour. For highly specific needs, you might even develop custom log parsers to pull out precise data points for in-depth analysis and reporting.

By effectively using Sitecore logs, organizations can significantly enhance system performance, troubleshoot and resolve issues more efficiently, strengthen their security, and ensure they meet all relevant regulations.

Conclusion:

In conclusion, Sitecore logging is far more than just a technical detail; it's an indispensable asset for maintaining a healthy, secure, and high-performing Sitecore environment. From providing granular insights into system performance and user behaviour to acting as the first line of defence in diagnosing errors and ensuring robust security, logs offer a comprehensive narrative of your solution's operations. By embracing proactive logging policies, leveraging automated analysis, and integrating with advanced monitoring tools, organizations can transform raw log data into actionable intelligence. This strategic approach empowers teams to identify and resolve issues swiftly, optimize resource utilization, uphold compliance standards, and ultimately deliver a superior digital experience. Therefore, a thorough understanding and effective utilization of Sitecore logs are paramount for any successful Sitecore implementation.

 

Bibliography

Sitecore Support

Sitecore Archive 1

Sitecore Archive 2

Sitecore Documentation