Skip to content

Commit f8f3a8b

Browse files
authored
Merge pull request #36 from aquality-automation/feature/separate-class-localized-logger
#33 Feature/separate class localized logger
2 parents a7a1382 + 8f5c82d commit f8f3a8b

File tree

10 files changed

+96
-73
lines changed

10 files changed

+96
-73
lines changed

Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.csproj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
</PropertyGroup>
66

7+
<ItemGroup>
8+
<None Remove="Resources\Localization\en.json" />
9+
<None Remove="Resources\Localization\ru.json" />
10+
</ItemGroup>
11+
712
<ItemGroup>
813
<EmbeddedResource Include="Resources\JavaScripts\AutoAcceptAlerts.js" />
914
<EmbeddedResource Include="Resources\JavaScripts\BorderElement.js" />
@@ -29,6 +34,8 @@
2934
<EmbeddedResource Include="Resources\JavaScripts\SetFocus.js" />
3035
<EmbeddedResource Include="Resources\JavaScripts\SetInnerHTML.js" />
3136
<EmbeddedResource Include="Resources\JavaScripts\SetValue.js" />
37+
<EmbeddedResource Include="Resources\Localization\en.json" />
38+
<EmbeddedResource Include="Resources\Localization\ru.json" />
3239
</ItemGroup>
3340

3441
<ItemGroup>
@@ -38,10 +45,6 @@
3845
<PackageReference Include="WebDriverManager" Version="2.5.1" />
3946
</ItemGroup>
4047

41-
<ItemGroup>
42-
<Folder Include="Resources\Logging\Localization\" />
43-
</ItemGroup>
44-
4548
<ItemGroup>
4649
<None Update="nlog.config">
4750
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserNavigation.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void Forward()
4343
/// <param name="url">String representation of URL.</param>
4444
public void GoToUrl(string url)
4545
{
46-
Logger.InfoLoc("loc.browser.navigate", url);
46+
InfoLocNavigate(url);
4747
driver.Navigate().GoToUrl(url);
4848
}
4949

@@ -53,7 +53,7 @@ public void GoToUrl(string url)
5353
/// <param name="url">Uri representation of URL.</param>
5454
public void GoToUrl(Uri url)
5555
{
56-
Logger.InfoLoc("loc.browser.navigate", url);
56+
InfoLocNavigate(url.ToString());
5757
driver.Navigate().GoToUrl(url);
5858
}
5959

@@ -65,5 +65,10 @@ public void Refresh()
6565
Logger.InfoLoc("loc.browser.refresh");
6666
driver.Navigate().Refresh();
6767
}
68+
69+
private void InfoLocNavigate(string url)
70+
{
71+
Logger.InfoLoc("loc.browser.navigate", url);
72+
}
6873
}
6974
}

Aquality.Selenium/src/Aquality.Selenium/Elements/Actions/CheckBoxJsActions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Aquality.Selenium.Browsers;
22
using Aquality.Selenium.Elements.Interfaces;
3+
using Aquality.Selenium.Logging;
34

45
namespace Aquality.Selenium.Elements.Actions
56
{
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
3+
namespace Aquality.Selenium.Localization
4+
{
5+
/// <summary>
6+
/// This class is using for translation messages to different languages
7+
/// </summary>
8+
internal sealed class LocalizationManager
9+
{
10+
private const string DefLocale = "en";
11+
private const string LocaleKey = "locale";
12+
private const string LangResources = "Resources.Localization.{0}.json";
13+
private static readonly Lazy<LocalizationManager> LazyInstance = new Lazy<LocalizationManager>(() => new LocalizationManager());
14+
15+
private LocalizationManager()
16+
{
17+
}
18+
19+
/// <summary>
20+
/// Gets LocalizationManager instance.
21+
/// </summary>
22+
public static LocalizationManager Instance => LazyInstance.Value;
23+
24+
/// <summary>
25+
/// Get localized message from resources by its key.
26+
/// </summary>
27+
/// <param name="messageKey">Key in resource file.</param>
28+
/// <param name="args">Arguments, which will be provided to template of localized message.</param>
29+
/// <returns>Localized message.</returns>
30+
public string GetLocalizedMessage(string messageKey, params string [] args)
31+
{
32+
throw new NotImplementedException();
33+
}
34+
}
35+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Aquality.Selenium.Localization
2+
{
3+
/// <summary>
4+
/// Supported locale.
5+
/// </summary>
6+
internal enum SupportedLocale
7+
{
8+
RU,
9+
EN
10+
}
11+
}

Aquality.Selenium/src/Aquality.Selenium/Logging/Logger.cs

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ namespace Aquality.Selenium.Logging
1010
/// </summary>
1111
public sealed class Logger
1212
{
13-
private const string DefLocale = "en";
14-
private const string LocaleKey = "logger.lang";
1513
private static readonly Lazy<Logger> LazyInstance = new Lazy<Logger>(() => new Logger());
1614
private static readonly ThreadLocal<ILogger> Log = new ThreadLocal<ILogger>(() => LogManager.GetLogger(Thread.CurrentThread.ManagedThreadId.ToString()));
1715

@@ -95,67 +93,5 @@ public void Fatal(string message, Exception exception)
9593
{
9694
Log.Value.Fatal(exception, message);
9795
}
98-
99-
/// <summary>
100-
/// Log localized info message.
101-
/// </summary>
102-
/// <param name="messageKey">Message messageKey from localization resources.</param>
103-
/// <param name="args">Arguments to be pasted into message via string.Format.</param>
104-
internal void InfoLoc(string messageKey, params object[] args)
105-
{
106-
Info(string.Format(GetLocalizedMessage(messageKey), args));
107-
}
108-
109-
/// <summary>
110-
/// Log localized debug message with optional exception.
111-
/// </summary>
112-
/// <param name="messageKey">Message messageKey from localization resources.</param>
113-
/// <param name="exception">Occurred exception.</param>
114-
/// <param name="args">Arguments to be pasted into message via string.Format.</param>
115-
internal void DebugLoc(string messageKey, Exception exception = null, params object[] args)
116-
{
117-
Debug(string.Format(GetLocalizedMessage(messageKey), args), exception);
118-
}
119-
120-
/// <summary>
121-
/// Log localized warning message.
122-
/// </summary>
123-
/// <param name="messageKey">Message messageKey from localization resources.</param>
124-
/// <param name="args">Arguments to be pasted into message via string.Format.</param>
125-
internal void WarnLoc(string messageKey, params object[] args)
126-
{
127-
Warn(string.Format(GetLocalizedMessage(messageKey), args));
128-
}
129-
130-
/// <summary>
131-
/// Log localized error message.
132-
/// </summary>
133-
/// <param name="messageKey">Message messageKey from localization resources.</param>
134-
/// <param name="args">Arguments to be pasted into message via string.Format</param>
135-
internal void ErrorLoc(string messageKey, params object[] args)
136-
{
137-
Error(string.Format(GetLocalizedMessage(messageKey), args));
138-
}
139-
140-
/// <summary>
141-
/// Log localized fatal message with exception.
142-
/// </summary>
143-
/// <param name="messageKey">Message messageKey from localization resources.</param>
144-
/// <param name="exception">Occurred exception.</param>
145-
/// <param name="args">Arguments to be pasted into message via string.Format.</param>
146-
internal void FatalLoc(string messageKey, Exception exception = null, params object[] args)
147-
{
148-
Fatal(string.Format(GetLocalizedMessage(messageKey), args), exception);
149-
}
150-
151-
/// <summary>
152-
/// Get localized message from resources by its key.
153-
/// </summary>
154-
/// <param name="messageKey">Key in resources file.</param>
155-
/// <returns>Template of message.</returns>
156-
private static string GetLocalizedMessage(string messageKey)
157-
{
158-
throw new NotImplementedException();
159-
}
16096
}
16197
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using Aquality.Selenium.Localization;
3+
4+
namespace Aquality.Selenium.Logging
5+
{
6+
internal static class LoggerExtension
7+
{
8+
public static void InfoLoc(this Logger logger, string messageKey, params string[] args)
9+
{
10+
logger.Info(LocalizationManager.Instance.GetLocalizedMessage(messageKey, args));
11+
}
12+
13+
public static void DebugLoc(this Logger logger, string messageKey, Exception exception = null, params string[] args)
14+
{
15+
logger.Debug(LocalizationManager.Instance.GetLocalizedMessage(messageKey, args), exception);
16+
}
17+
18+
public static void WarnLoc(this Logger logger, string messageKey, params string[] args)
19+
{
20+
logger.Warn(LocalizationManager.Instance.GetLocalizedMessage(messageKey, args));
21+
}
22+
23+
public static void ErrorLoc(this Logger logger, string messageKey, params string[] args)
24+
{
25+
logger.Error(LocalizationManager.Instance.GetLocalizedMessage(messageKey, args));
26+
}
27+
28+
public static void FatalLoc(this Logger logger, string messageKey, Exception exception = null, params string[] args)
29+
{
30+
logger.Fatal(LocalizationManager.Instance.GetLocalizedMessage(messageKey, args), exception);
31+
}
32+
}
33+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}

Aquality.Selenium/src/Aquality.Selenium/Resources/Logging/loglang.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)