Skip to content

Commit dd5c16d

Browse files
committed
Add CompositeFormat for log
1 parent df5fd91 commit dd5c16d

7 files changed

Lines changed: 75 additions & 36 deletions

File tree

.gitignore

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*.user
1010
*.userosscache
1111
*.sln.docstates
12+
*.env
1213

1314
# User-specific files (MonoDevelop/Xamarin Studio)
1415
*.userprefs
@@ -21,16 +22,36 @@ mono_crash.*
2122
[Dd]ebugPublic/
2223
[Rr]elease/
2324
[Rr]eleases/
24-
x64/
25-
x86/
25+
26+
[Dd]ebug/x64/
27+
[Dd]ebugPublic/x64/
28+
[Rr]elease/x64/
29+
[Rr]eleases/x64/
30+
bin/x64/
31+
obj/x64/
32+
33+
[Dd]ebug/x86/
34+
[Dd]ebugPublic/x86/
35+
[Rr]elease/x86/
36+
[Rr]eleases/x86/
37+
bin/x86/
38+
obj/x86/
39+
2640
[Ww][Ii][Nn]32/
2741
[Aa][Rr][Mm]/
2842
[Aa][Rr][Mm]64/
43+
[Aa][Rr][Mm]64[Ee][Cc]/
2944
bld/
30-
[Bb]in/
3145
[Oo]bj/
46+
[Oo]ut/
3247
[Ll]og/
33-
#[Ll]ogs/
48+
[Ll]ogs/
49+
50+
# Build results on 'Bin' directories
51+
**/[Bb]in/*
52+
# Uncomment if you have tasks that rely on *.refresh files to move binaries
53+
# (https://github.com/github/gitignore/pull/3736)
54+
#!**/[Bb]in/*.refresh
3455

3556
# Visual Studio 2015/2017 cache/options directory
3657
.vs/
@@ -43,12 +64,16 @@ Generated\ Files/
4364
# MSTest test Results
4465
[Tt]est[Rr]esult*/
4566
[Bb]uild[Ll]og.*
67+
*.trx
4668

4769
# NUnit
4870
*.VisualState.xml
4971
TestResult.xml
5072
nunit-*.xml
5173

74+
# Approval Tests result files
75+
*.received.*
76+
5277
# Build Results of an ATL Project
5378
[Dd]ebugPS/
5479
[Rr]eleasePS/
@@ -75,6 +100,7 @@ StyleCopReport.xml
75100
*.ilk
76101
*.meta
77102
*.obj
103+
*.idb
78104
*.iobj
79105
*.pch
80106
*.pdb
@@ -155,6 +181,7 @@ coverage*.info
155181

156182
# NCrunch
157183
_NCrunch_*
184+
.NCrunch_*
158185
.*crunch*.local.xml
159186
nCrunchTemp_*
160187

@@ -296,9 +323,6 @@ node_modules/
296323
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
297324
*.vbw
298325

299-
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
300-
*.vbp
301-
302326
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
303327
*.dsw
304328
*.dsp
@@ -316,22 +340,22 @@ node_modules/
316340
_Pvt_Extensions
317341

318342
# Paket dependency manager
319-
.paket/paket.exe
343+
**/.paket/paket.exe
320344
paket-files/
321345

322346
# FAKE - F# Make
323-
.fake/
347+
**/.fake/
324348

325349
# CodeRush personal settings
326-
.cr/personal
350+
**/.cr/personal
327351

328352
# Python Tools for Visual Studio (PTVS)
329-
__pycache__/
353+
**/__pycache__/
330354
*.pyc
331355

332356
# Cake - Uncomment if you are using it
333-
# tools/**
334-
# !tools/packages.config
357+
#tools/**
358+
#!tools/packages.config
335359

336360
# Tabs Studio
337361
*.tss
@@ -353,15 +377,19 @@ ASALocalRun/
353377

354378
# MSBuild Binary and Structured Log
355379
*.binlog
380+
MSBuild_Logs/
381+
382+
# AWS SAM Build and Temporary Artifacts folder
383+
.aws-sam
356384

357385
# NVidia Nsight GPU debugger configuration file
358386
*.nvuser
359387

360388
# MFractors (Xamarin productivity tool) working folder
361-
.mfractor/
389+
**/.mfractor/
362390

363391
# Local History for Visual Studio
364-
.localhistory/
392+
**/.localhistory/
365393

366394
# Visual Studio History (VSHistory) files
367395
.vshistory/
@@ -373,7 +401,7 @@ healthchecksdb
373401
MigrationBackup/
374402

375403
# Ionide (cross platform F# VS Code tools) working folder
376-
.ionide/
404+
**/.ionide/
377405

378406
# Fody - auto-generated XML schema
379407
FodyWeavers.xsd
@@ -384,17 +412,20 @@ FodyWeavers.xsd
384412
!.vscode/tasks.json
385413
!.vscode/launch.json
386414
!.vscode/extensions.json
387-
*.code-workspace
415+
!.vscode/*.code-snippets
388416

389417
# Local History for Visual Studio Code
390418
.history/
391419

420+
# Built Visual Studio Code Extensions
421+
*.vsix
422+
392423
# Windows Installer files from build outputs
393424
*.cab
394425
*.msi
395426
*.msix
396427
*.msm
397428
*.msp
398429

399-
# JetBrains Rider
400-
*.sln.iml
430+
# VS Code C# Dev Kit
431+
*.lscache

AdvancedSharpAdbClient/AdbClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public static byte[] CreateAdbForwardRequest(scoped ReadOnlySpan<char> address,
213213
scoped DefaultInterpolatedStringHandler request = address.IsEmpty ? (DefaultInterpolatedStringHandler)$"tcp:{port}" : $"tcp:{port}:{address}";
214214
return FormAdbRequest(request.Text);
215215
#else
216-
string request = address == null ? $"tcp:{port}" : $"tcp:{port}:{address}";
216+
string request = address.Length > 0 ? $"tcp:{port}:{address}" : $"tcp:{port}";
217217
return FormAdbRequest(request);
218218
#endif
219219
}

AdvancedSharpAdbClient/AdbServer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ public AdbServer(Func<EndPoint, IAdbSocket> adbSocketFactory, Func<string, IAdbC
149149
/// <summary>
150150
/// Gets or sets the default instance of the <see cref="IAdbServer"/> interface.
151151
/// </summary>
152-
public static IAdbServer Instance { get; set; } = new AdbServer();
152+
public static IAdbServer Instance
153+
{
154+
get => field ??= new AdbServer();
155+
set;
156+
}
153157

154158
/// <summary>
155159
/// <see langword="true"/> if is starting adb server; otherwise, <see langword="false"/>.

AdvancedSharpAdbClient/AdvancedSharpAdbClient.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
System.Diagnostics.CodeAnalysis.NotNullAttribute;
3535
System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute;
3636
System.Diagnostics.CodeAnalysis.NotNullWhenAttribute;
37+
System.Diagnostics.CodeAnalysis.StringSyntaxAttribute;
3738
System.Diagnostics.StackTraceHiddenAttribute;
3839
System.Index;
3940
System.Range;

AdvancedSharpAdbClient/Extensions/LoggerExtensions.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// </copyright>
44

55
using System;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.Runtime.CompilerServices;
78

89
namespace AdvancedSharpAdbClient.Logs
@@ -23,7 +24,7 @@ public static class LoggerExtensions
2324
/// <param name="args">An object array that contains zero or more objects to format.</param>
2425
/// <example>logger.LogDebug(exception, "Error while processing request from {Address}", address)</example>
2526
[MethodImpl((MethodImplOptions)0x100)]
26-
public static void LogDebug(this ILogger logger, Exception? exception, string? message, params object?[] args) =>
27+
public static void LogDebug(this ILogger logger, Exception? exception, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[] args) =>
2728
logger.Log(LogLevel.Debug, exception, message, args);
2829

2930
/// <summary>
@@ -34,7 +35,7 @@ public static void LogDebug(this ILogger logger, Exception? exception, string? m
3435
/// <param name="args">An object array that contains zero or more objects to format.</param>
3536
/// <example>logger.LogDebug("Processing request from {Address}", address)</example>
3637
[MethodImpl((MethodImplOptions)0x100)]
37-
public static void LogDebug(this ILogger logger, string? message, params object?[] args) =>
38+
public static void LogDebug(this ILogger logger, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[] args) =>
3839
logger.Log(LogLevel.Debug, message, args);
3940

4041
//------------------------------------------TRACE------------------------------------------//
@@ -48,7 +49,7 @@ public static void LogDebug(this ILogger logger, string? message, params object?
4849
/// <param name="args">An object array that contains zero or more objects to format.</param>
4950
/// <example>logger.LogTrace(exception, "Error while processing request from {Address}", address)</example>
5051
[MethodImpl((MethodImplOptions)0x100)]
51-
public static void LogTrace(this ILogger logger, Exception? exception, string? message, params object?[] args) =>
52+
public static void LogTrace(this ILogger logger, Exception? exception, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[] args) =>
5253
logger.Log(LogLevel.Trace, exception, message, args);
5354

5455
/// <summary>
@@ -59,7 +60,7 @@ public static void LogTrace(this ILogger logger, Exception? exception, string? m
5960
/// <param name="args">An object array that contains zero or more objects to format.</param>
6061
/// <example>logger.LogTrace("Processing request from {Address}", address)</example>
6162
[MethodImpl((MethodImplOptions)0x100)]
62-
public static void LogTrace(this ILogger logger, string? message, params object?[] args) =>
63+
public static void LogTrace(this ILogger logger, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[] args) =>
6364
logger.Log(LogLevel.Trace, message, args);
6465

6566
//------------------------------------------INFORMATION------------------------------------------//
@@ -73,7 +74,7 @@ public static void LogTrace(this ILogger logger, string? message, params object?
7374
/// <param name="args">An object array that contains zero or more objects to format.</param>
7475
/// <example>logger.LogInformation(exception, "Error while processing request from {Address}", address)</example>
7576
[MethodImpl((MethodImplOptions)0x100)]
76-
public static void LogInformation(this ILogger logger, Exception? exception, string? message, params object?[] args) =>
77+
public static void LogInformation(this ILogger logger, Exception? exception, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[] args) =>
7778
logger.Log(LogLevel.Information, exception, message, args);
7879

7980
/// <summary>
@@ -84,7 +85,7 @@ public static void LogInformation(this ILogger logger, Exception? exception, str
8485
/// <param name="args">An object array that contains zero or more objects to format.</param>
8586
/// <example>logger.LogInformation("Processing request from {Address}", address)</example>
8687
[MethodImpl((MethodImplOptions)0x100)]
87-
public static void LogInformation(this ILogger logger, string? message, params object?[] args) =>
88+
public static void LogInformation(this ILogger logger, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[] args) =>
8889
logger.Log(LogLevel.Information, message, args);
8990

9091
//------------------------------------------WARNING------------------------------------------//
@@ -98,7 +99,7 @@ public static void LogInformation(this ILogger logger, string? message, params o
9899
/// <param name="args">An object array that contains zero or more objects to format.</param>
99100
/// <example>logger.LogWarning(exception, "Error while processing request from {Address}", address)</example>
100101
[MethodImpl((MethodImplOptions)0x100)]
101-
public static void LogWarning(this ILogger logger, Exception? exception, string? message, params object?[] args) =>
102+
public static void LogWarning(this ILogger logger, Exception? exception, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[] args) =>
102103
logger.Log(LogLevel.Warning, exception, message, args);
103104

104105
/// <summary>
@@ -109,7 +110,7 @@ public static void LogWarning(this ILogger logger, Exception? exception, string?
109110
/// <param name="args">An object array that contains zero or more objects to format.</param>
110111
/// <example>logger.LogWarning("Processing request from {Address}", address)</example>
111112
[MethodImpl((MethodImplOptions)0x100)]
112-
public static void LogWarning(this ILogger logger, string? message, params object?[] args) =>
113+
public static void LogWarning(this ILogger logger, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[] args) =>
113114
logger.Log(LogLevel.Warning, message, args);
114115

115116
//------------------------------------------ERROR------------------------------------------//
@@ -123,7 +124,7 @@ public static void LogWarning(this ILogger logger, string? message, params objec
123124
/// <param name="args">An object array that contains zero or more objects to format.</param>
124125
/// <example>logger.LogError(exception, "Error while processing request from {Address}", address)</example>
125126
[MethodImpl((MethodImplOptions)0x100)]
126-
public static void LogError(this ILogger logger, Exception? exception, string? message, params object?[] args) =>
127+
public static void LogError(this ILogger logger, Exception? exception, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[] args) =>
127128
logger.Log(LogLevel.Error, exception, message, args);
128129

129130
/// <summary>
@@ -134,7 +135,7 @@ public static void LogError(this ILogger logger, Exception? exception, string? m
134135
/// <param name="args">An object array that contains zero or more objects to format.</param>
135136
/// <example>logger.LogError("Processing request from {Address}", address)</example>
136137
[MethodImpl((MethodImplOptions)0x100)]
137-
public static void LogError(this ILogger logger, string? message, params object?[] args) =>
138+
public static void LogError(this ILogger logger, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[] args) =>
138139
logger.Log(LogLevel.Error, message, args);
139140

140141
//------------------------------------------CRITICAL------------------------------------------//
@@ -148,7 +149,7 @@ public static void LogError(this ILogger logger, string? message, params object?
148149
/// <param name="args">An object array that contains zero or more objects to format.</param>
149150
/// <example>logger.LogCritical(exception, "Error while processing request from {Address}", address)</example>
150151
[MethodImpl((MethodImplOptions)0x100)]
151-
public static void LogCritical(this ILogger logger, Exception? exception, string? message, params object?[] args) =>
152+
public static void LogCritical(this ILogger logger, Exception? exception, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[] args) =>
152153
logger.Log(LogLevel.Critical, exception, message, args);
153154

154155
/// <summary>
@@ -159,7 +160,7 @@ public static void LogCritical(this ILogger logger, Exception? exception, string
159160
/// <param name="args">An object array that contains zero or more objects to format.</param>
160161
/// <example>logger.LogCritical("Processing request from {Address}", address)</example>
161162
[MethodImpl((MethodImplOptions)0x100)]
162-
public static void LogCritical(this ILogger logger, string? message, params object?[] args) =>
163+
public static void LogCritical(this ILogger logger, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[] args) =>
163164
logger.Log(LogLevel.Critical, message, args);
164165

165166
/// <summary>
@@ -170,7 +171,7 @@ public static void LogCritical(this ILogger logger, string? message, params obje
170171
/// <param name="message">Format string of the log message.</param>
171172
/// <param name="args">An object array that contains zero or more objects to format.</param>
172173
[MethodImpl((MethodImplOptions)0x100)]
173-
public static void Log(this ILogger logger, LogLevel logLevel, string? message, params object?[] args) =>
174+
public static void Log(this ILogger logger, LogLevel logLevel, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[] args) =>
174175
logger.Log(logLevel, null, message, args);
175176
}
176177
}

AdvancedSharpAdbClient/Logs/Interfaces/ILogger.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// </copyright>
44

55
using System;
6+
using System.Diagnostics.CodeAnalysis;
67

78
namespace AdvancedSharpAdbClient.Logs
89
{
@@ -19,7 +20,7 @@ public interface ILogger
1920
/// <param name="exception">The exception to log.</param>
2021
/// <param name="message">Format string of the log message.</param>
2122
/// <param name="args">An object array that contains zero or more objects to format.</param>
22-
void Log(LogLevel logLevel, Exception? exception, string? message, params object?[] args);
23+
void Log(LogLevel logLevel, Exception? exception, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[] args);
2324
}
2425

2526
/// <summary>

AdvancedSharpAdbClient/Logs/NullLogger.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// </copyright>
44

55
using System;
6+
using System.Diagnostics.CodeAnalysis;
67

78
namespace AdvancedSharpAdbClient.Logs
89
{
@@ -17,7 +18,7 @@ public class NullLogger : ILogger
1718
public static NullLogger Instance { get; } = new();
1819

1920
/// <inheritdoc />
20-
public void Log(LogLevel logLevel, Exception? exception, string? message, params object?[] args) { }
21+
public void Log(LogLevel logLevel, Exception? exception, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message, params object?[] args) { }
2122
}
2223

2324
/// <summary>

0 commit comments

Comments
 (0)