Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit cf31b5b

Browse files
committed
Implement OrmLiteConfig.ResetLogFactory
1 parent 371285f commit cf31b5b

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

src/ServiceStack.OrmLite/OrmLiteConfig.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System;
1313
using System.Collections.Generic;
1414
using System.Data;
15+
using ServiceStack.Logging;
1516

1617
namespace ServiceStack.OrmLite
1718
{
@@ -147,6 +148,12 @@ public static IDbConnection ToDbConnection(this string dbConnectionStringOrFileP
147148
return dbConn;
148149
}
149150

151+
public static void ResetLogFactory(ILogFactory logFactory)
152+
{
153+
LogManager.LogFactory = logFactory;
154+
OrmLiteResultsFilterExtensions.Log = LogManager.LogFactory.GetLogger(typeof(OrmLiteResultsFilterExtensions));
155+
}
156+
150157
public static bool DisableColumnGuessFallback { get; set; }
151158
public static bool StripUpperInLike { get; set; }
152159
#if NETSTANDARD1_3

src/ServiceStack.OrmLite/OrmLiteResultsFilterExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace ServiceStack.OrmLite
1212
{
1313
public static class OrmLiteResultsFilterExtensions
1414
{
15-
private static readonly ILog Log = LogManager.GetLogger(typeof(OrmLiteResultsFilterExtensions));
15+
internal static ILog Log = LogManager.GetLogger(typeof(OrmLiteResultsFilterExtensions));
1616

1717
public static int ExecNonQuery(this IDbCommand dbCmd, string sql, object anonType = null)
1818
{

tests/ServiceStack.OrmLite.Tests/Issues/NoSqlLoggingIssue.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,30 @@ namespace ServiceStack.OrmLite.Tests.Issues
66
{
77
public class NoSqlLoggingIssue : OrmLiteTestBase
88
{
9-
//NUnit in .NET Core not liking resetting AppDomain after each TestFixture
10-
#if !NETCORE
9+
[Test]
10+
public void Does_log_SQL_Insert_for_Saves()
11+
{
12+
var sbLogFactory = new StringBuilderLogFactory();
13+
OrmLiteConfig.ResetLogFactory(sbLogFactory);
14+
15+
using (var db = OpenDbConnection())
16+
{
17+
db.DropAndCreateTable<Person>();
18+
19+
db.Save(new Person { Id = 1, FirstName = "first", LastName = "last", Age = 27 });
20+
}
21+
22+
var sql = sbLogFactory.GetLogs();
23+
24+
Assert.That(sql, Does.Contain("INSERT INTO"));
25+
OrmLiteConfig.ResetLogFactory(null);
26+
}
27+
1128
[Test]
1229
public void Does_log_SQL_Insert_for_Saves_with_Auto_Ids()
1330
{
1431
var sbLogFactory = new StringBuilderLogFactory();
15-
LogManager.LogFactory = sbLogFactory;
32+
OrmLiteConfig.ResetLogFactory(sbLogFactory);
1633

1734
using (var db = OpenDbConnection())
1835
{
@@ -24,8 +41,7 @@ public void Does_log_SQL_Insert_for_Saves_with_Auto_Ids()
2441
var sql = sbLogFactory.GetLogs();
2542

2643
Assert.That(sql, Does.Contain("INSERT INTO"));
27-
LogManager.LogFactory = null;
44+
OrmLiteConfig.ResetLogFactory(null);
2845
}
29-
#endif
3046
}
3147
}

0 commit comments

Comments
 (0)