mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Implementing log for Azure
--HG-- branch : 1.x
This commit is contained in:
40
src/Orchard.Azure/Logging/AzureAppender.cs
Normal file
40
src/Orchard.Azure/Logging/AzureAppender.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using Microsoft.WindowsAzure;
|
||||
using Microsoft.WindowsAzure.Diagnostics.Management;
|
||||
using Microsoft.WindowsAzure.ServiceRuntime;
|
||||
using log4net.Appender;
|
||||
using log4net.Core;
|
||||
|
||||
namespace Orchard.Azure.Logging {
|
||||
|
||||
/// <summary>
|
||||
/// Azure specific implementation of a log4net appender.
|
||||
/// Uses DataConnectionString to define the location of the log.
|
||||
/// </summary>
|
||||
public class AzureAppender : AppenderSkeleton {
|
||||
private const string WadConnectionString = "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString";
|
||||
|
||||
public AzureAppender() {
|
||||
|
||||
var cloudStorageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(WadConnectionString));
|
||||
|
||||
var roleInstanceDiagnosticManager = cloudStorageAccount.CreateRoleInstanceDiagnosticManager(
|
||||
RoleEnvironment.DeploymentId,
|
||||
RoleEnvironment.CurrentRoleInstance.Role.Name,
|
||||
RoleEnvironment.CurrentRoleInstance.Id);
|
||||
|
||||
var diagnosticMonitorConfiguration = roleInstanceDiagnosticManager.GetCurrentConfiguration();
|
||||
diagnosticMonitorConfiguration.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1d);
|
||||
diagnosticMonitorConfiguration.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1d);
|
||||
|
||||
roleInstanceDiagnosticManager.SetCurrentConfiguration(diagnosticMonitorConfiguration);
|
||||
}
|
||||
|
||||
protected override void Append(LoggingEvent loggingEvent) {
|
||||
var formattedLog = RenderLoggingEvent(loggingEvent);
|
||||
|
||||
// this is the way to logging into Azure
|
||||
System.Diagnostics.Trace.WriteLine(formattedLog);
|
||||
}
|
||||
}
|
||||
}
|
@@ -4,6 +4,7 @@
|
||||
<Instances count="1" />
|
||||
<ConfigurationSettings>
|
||||
<Setting name="DataConnectionString" value="UseDevelopmentStorage=true" />
|
||||
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
|
||||
</ConfigurationSettings>
|
||||
</Role>
|
||||
</ServiceConfiguration>
|
@@ -8,6 +8,9 @@
|
||||
</Bindings>
|
||||
</Site>
|
||||
</Sites>
|
||||
<Imports>
|
||||
<Import moduleName="Diagnostics" />
|
||||
</Imports>
|
||||
<ConfigurationSettings>
|
||||
<Setting name="DataConnectionString" />
|
||||
</ConfigurationSettings>
|
||||
|
@@ -3,26 +3,25 @@
|
||||
<root>
|
||||
<!-- Value of priority may be ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF -->
|
||||
<priority value="WARN" />
|
||||
<appender-ref ref="RollingLogFileAppender" />
|
||||
<appender-ref ref="AzureAppender" />
|
||||
</root>
|
||||
|
||||
<!--
|
||||
<logger name="Orchard.Localization">
|
||||
<priority value="WARN" />
|
||||
<appender-ref ref="RollingLogFileAppender" />
|
||||
</logger>
|
||||
-->
|
||||
|
||||
<logger name="Orchard.Data.SessionLocator">
|
||||
<priority value="INFO" />
|
||||
<appender-ref ref="RollingLogFileAppender" />
|
||||
</logger>
|
||||
|
||||
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
|
||||
<file value="App_Data/Logs/orchard-debug.txt" />
|
||||
<appendToFile value="true" />
|
||||
<immediateFlush value="true" />
|
||||
<appender name="AzureAppender" type="Orchard.Logging.AzureAppender">
|
||||
|
||||
<filter type="log4net.Filter.LevelRangeFilter">
|
||||
<!-- only error and fatal messages end up in this target, even if child loggers accept lower priority -->
|
||||
<levelMin value="ERROR" />
|
||||
</filter>
|
||||
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%logger - %message%newline" />
|
||||
<conversionPattern value="%date [%thread] %logger - %message%newline" />
|
||||
</layout>
|
||||
</appender>
|
||||
</log4net>
|
||||
|
@@ -36,6 +36,20 @@
|
||||
</namespaces>
|
||||
</pages>
|
||||
</system.web.webPages.razor>
|
||||
|
||||
<system.diagnostics>
|
||||
<trace>
|
||||
<listeners>
|
||||
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener,
|
||||
Microsoft.WindowsAzure.Diagnostics,
|
||||
Version=1.0.0.0,
|
||||
Culture=neutral,
|
||||
PublicKeyToken=31bf3856ad364e35"
|
||||
name="AzureDiagnostics">
|
||||
</add>
|
||||
</listeners>
|
||||
</trace>
|
||||
</system.diagnostics>
|
||||
|
||||
<!--
|
||||
Set default transaction timeout to 30 minutes so that interactive debugging
|
||||
|
@@ -53,6 +53,11 @@
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="log4net">
|
||||
<HintPath>..\..\lib\fluentnhibernate\log4net.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
|
||||
<Reference Include="Microsoft.WindowsAzure.ServiceRuntime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
|
||||
<Reference Include="Microsoft.WindowsAzure.StorageClient, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
@@ -76,6 +81,7 @@
|
||||
<Compile Include="HttpContextWeaver.cs" />
|
||||
<Compile Include="Environment\Configuration\AzureShellSettingsManager.cs" />
|
||||
<Compile Include="FileSystems\Media\AzureBlobStorageProvider.cs" />
|
||||
<Compile Include="Logging\AzureAppender.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="AzureFileSystem.cs" />
|
||||
</ItemGroup>
|
||||
@@ -103,6 +109,7 @@
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
Reference in New Issue
Block a user