mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-03 03:58:13 +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" />
|
<Instances count="1" />
|
||||||
<ConfigurationSettings>
|
<ConfigurationSettings>
|
||||||
<Setting name="DataConnectionString" value="UseDevelopmentStorage=true" />
|
<Setting name="DataConnectionString" value="UseDevelopmentStorage=true" />
|
||||||
|
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
|
||||||
</ConfigurationSettings>
|
</ConfigurationSettings>
|
||||||
</Role>
|
</Role>
|
||||||
</ServiceConfiguration>
|
</ServiceConfiguration>
|
||||||
@@ -8,6 +8,9 @@
|
|||||||
</Bindings>
|
</Bindings>
|
||||||
</Site>
|
</Site>
|
||||||
</Sites>
|
</Sites>
|
||||||
|
<Imports>
|
||||||
|
<Import moduleName="Diagnostics" />
|
||||||
|
</Imports>
|
||||||
<ConfigurationSettings>
|
<ConfigurationSettings>
|
||||||
<Setting name="DataConnectionString" />
|
<Setting name="DataConnectionString" />
|
||||||
</ConfigurationSettings>
|
</ConfigurationSettings>
|
||||||
|
|||||||
@@ -3,26 +3,25 @@
|
|||||||
<root>
|
<root>
|
||||||
<!-- Value of priority may be ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF -->
|
<!-- Value of priority may be ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF -->
|
||||||
<priority value="WARN" />
|
<priority value="WARN" />
|
||||||
<appender-ref ref="RollingLogFileAppender" />
|
<appender-ref ref="AzureAppender" />
|
||||||
</root>
|
</root>
|
||||||
|
|
||||||
|
<!--
|
||||||
<logger name="Orchard.Localization">
|
<logger name="Orchard.Localization">
|
||||||
<priority value="WARN" />
|
<priority value="WARN" />
|
||||||
<appender-ref ref="RollingLogFileAppender" />
|
<appender-ref ref="RollingLogFileAppender" />
|
||||||
</logger>
|
</logger>
|
||||||
|
-->
|
||||||
|
|
||||||
<logger name="Orchard.Data.SessionLocator">
|
<appender name="AzureAppender" type="Orchard.Logging.AzureAppender">
|
||||||
<priority value="INFO" />
|
|
||||||
<appender-ref ref="RollingLogFileAppender" />
|
|
||||||
</logger>
|
|
||||||
|
|
||||||
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
|
<filter type="log4net.Filter.LevelRangeFilter">
|
||||||
<file value="App_Data/Logs/orchard-debug.txt" />
|
<!-- only error and fatal messages end up in this target, even if child loggers accept lower priority -->
|
||||||
<appendToFile value="true" />
|
<levelMin value="ERROR" />
|
||||||
<immediateFlush value="true" />
|
</filter>
|
||||||
|
|
||||||
<layout type="log4net.Layout.PatternLayout">
|
<layout type="log4net.Layout.PatternLayout">
|
||||||
<conversionPattern value="%logger - %message%newline" />
|
<conversionPattern value="%date [%thread] %logger - %message%newline" />
|
||||||
</layout>
|
</layout>
|
||||||
</appender>
|
</appender>
|
||||||
</log4net>
|
</log4net>
|
||||||
|
|||||||
@@ -37,6 +37,20 @@
|
|||||||
</pages>
|
</pages>
|
||||||
</system.web.webPages.razor>
|
</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
|
Set default transaction timeout to 30 minutes so that interactive debugging
|
||||||
is easier (default timeout is less than one minute)
|
is easier (default timeout is less than one minute)
|
||||||
|
|||||||
@@ -53,6 +53,11 @@
|
|||||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<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.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">
|
<Reference Include="Microsoft.WindowsAzure.StorageClient, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
@@ -76,6 +81,7 @@
|
|||||||
<Compile Include="HttpContextWeaver.cs" />
|
<Compile Include="HttpContextWeaver.cs" />
|
||||||
<Compile Include="Environment\Configuration\AzureShellSettingsManager.cs" />
|
<Compile Include="Environment\Configuration\AzureShellSettingsManager.cs" />
|
||||||
<Compile Include="FileSystems\Media\AzureBlobStorageProvider.cs" />
|
<Compile Include="FileSystems\Media\AzureBlobStorageProvider.cs" />
|
||||||
|
<Compile Include="Logging\AzureAppender.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="AzureFileSystem.cs" />
|
<Compile Include="AzureFileSystem.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -103,6 +109,7 @@
|
|||||||
<Install>true</Install>
|
<Install>true</Install>
|
||||||
</BootstrapperPackage>
|
</BootstrapperPackage>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup />
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- 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.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|||||||
Reference in New Issue
Block a user